2017-08-04 06:12:30 +08:00
|
|
|
//===- MipsInstrInfo.h - Mips Instruction Information -----------*- C++ -*-===//
|
2007-06-06 15:42:06 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
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"
|
2017-11-08 09:01:31 +08:00
|
|
|
#include "llvm/CodeGen/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;
|
|
|
|
|
2018-05-16 18:03:05 +08:00
|
|
|
/// Determine if the branch target is in range.
|
|
|
|
bool isBranchOffsetInRange(unsigned BranchOpc,
|
|
|
|
int64_t BrOffset) const override;
|
|
|
|
|
2016-03-15 00:24:05 +08:00
|
|
|
/// 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
|
|
|
|
2020-03-27 16:11:48 +08:00
|
|
|
virtual bool isBranchWithImm(unsigned Opc) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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,
|
[NFC] unsigned->Register in storeRegTo/loadRegFromStack
Summary:
This patch makes progress on the 'unsigned -> Register' rewrite for
`TargetInstrInfo::loadRegFromStack` and `TII::storeRegToStack`.
Reviewers: arsenm, craig.topper, uweigand, jpienaar, atanasyan, venkatra, robertlytton, dylanmckay, t.p.northover, kparzysz, tstellar, k-ishizaka
Reviewed By: arsenm
Subscribers: wuzish, merge_guards_bot, jyknight, sdardis, nemanjai, jvesely, wdng, nhaehnle, hiraditya, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, Jim, lenary, s.egerton, pzheng, sameer.abuasal, apazos, luismarques, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73870
2020-02-03 21:22:06 +08:00
|
|
|
Register SrcReg, bool isKill, int FrameIndex,
|
2014-04-29 15:58:02 +08:00
|
|
|
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,
|
[NFC] unsigned->Register in storeRegTo/loadRegFromStack
Summary:
This patch makes progress on the 'unsigned -> Register' rewrite for
`TargetInstrInfo::loadRegFromStack` and `TII::storeRegToStack`.
Reviewers: arsenm, craig.topper, uweigand, jpienaar, atanasyan, venkatra, robertlytton, dylanmckay, t.p.northover, kparzysz, tstellar, k-ishizaka
Reviewed By: arsenm
Subscribers: wuzish, merge_guards_bot, jyknight, sdardis, nemanjai, jvesely, wdng, nhaehnle, hiraditya, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, Jim, lenary, s.egerton, pzheng, sameer.abuasal, apazos, luismarques, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73870
2020-02-03 21:22:06 +08:00
|
|
|
Register DestReg, int FrameIndex,
|
2014-04-29 15:58:02 +08:00
|
|
|
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,
|
[NFC] unsigned->Register in storeRegTo/loadRegFromStack
Summary:
This patch makes progress on the 'unsigned -> Register' rewrite for
`TargetInstrInfo::loadRegFromStack` and `TII::storeRegToStack`.
Reviewers: arsenm, craig.topper, uweigand, jpienaar, atanasyan, venkatra, robertlytton, dylanmckay, t.p.northover, kparzysz, tstellar, k-ishizaka
Reviewed By: arsenm
Subscribers: wuzish, merge_guards_bot, jyknight, sdardis, nemanjai, jvesely, wdng, nhaehnle, hiraditya, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, Jim, lenary, s.egerton, pzheng, sameer.abuasal, apazos, luismarques, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73870
2020-02-03 21:22:06 +08:00
|
|
|
Register SrcReg, bool isKill, int FrameIndex,
|
2013-03-29 10:14:12 +08:00
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
const TargetRegisterInfo *TRI,
|
|
|
|
int64_t Offset) const = 0;
|
|
|
|
|
|
|
|
virtual void loadRegFromStack(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
[NFC] unsigned->Register in storeRegTo/loadRegFromStack
Summary:
This patch makes progress on the 'unsigned -> Register' rewrite for
`TargetInstrInfo::loadRegFromStack` and `TII::storeRegToStack`.
Reviewers: arsenm, craig.topper, uweigand, jpienaar, atanasyan, venkatra, robertlytton, dylanmckay, t.p.northover, kparzysz, tstellar, k-ishizaka
Reviewed By: arsenm
Subscribers: wuzish, merge_guards_bot, jyknight, sdardis, nemanjai, jvesely, wdng, nhaehnle, hiraditya, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, Jim, lenary, s.egerton, pzheng, sameer.abuasal, apazos, luismarques, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73870
2020-02-03 21:22:06 +08:00
|
|
|
Register DestReg, int FrameIndex,
|
2013-03-29 10:14:12 +08:00
|
|
|
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;
|
|
|
|
|
2019-09-25 22:55:57 +08:00
|
|
|
bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx1,
|
2017-03-31 22:31:55 +08:00
|
|
|
unsigned &SrcOpIdx2) const override;
|
|
|
|
|
[mips] Pick the right variant of DINS upfront and enable target instruction verification
This patch complements D16810 "[mips] Make isel select the correct DEXT variant
up front.". Now ISel picks the right variant of DINS, so now there is no need
to replace DINS with the appropriate variant during
MipsMCCodeEmitter::encodeInstruction().
This patch also enables target specific instruction verification for ins, dins,
dinsm, dinsu, ext, dext, dextm, dextu. These instructions have constraints that
are checked when generating MipsISD::Ins and MipsISD::Ext nodes, but these
constraints are not checked during instruction selection. Adding machine
verification should catch outstanding cases.
Finally, correct a bug that instruction verification uncovered, where the
position operand of a DINSU generated during lowering was being silently
and accidently corrected to the correct value.
Reviewers: slthakur
Differential Revision: https://reviews.llvm.org/D34809
llvm-svn: 313254
2017-09-14 18:58:00 +08:00
|
|
|
/// Perform target specific instruction verification.
|
|
|
|
bool verifyInstruction(const MachineInstr &MI,
|
|
|
|
StringRef &ErrInfo) const override;
|
|
|
|
|
2017-10-11 19:11:35 +08:00
|
|
|
std::pair<unsigned, unsigned>
|
|
|
|
decomposeMachineOperandsTargetFlags(unsigned TF) const override;
|
|
|
|
|
|
|
|
ArrayRef<std::pair<unsigned, const char *>>
|
|
|
|
getSerializableDirectMachineOperandTargetFlags() 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
|