2017-08-04 06:12:30 +08:00
|
|
|
//===- MipsInstrInfo.cpp - Mips Instruction Information -------------------===//
|
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
|
|
|
|
|
|
|
#include "MipsInstrInfo.h"
|
2017-08-04 06:12:30 +08:00
|
|
|
#include "MCTargetDesc/MipsBaseInfo.h"
|
|
|
|
#include "MCTargetDesc/MipsMCTargetDesc.h"
|
2015-01-09 02:18:54 +08:00
|
|
|
#include "MipsSubtarget.h"
|
2017-08-04 06:12:30 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2007-06-06 15:42:06 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2017-08-04 06:12:30 +08:00
|
|
|
#include "llvm/CodeGen/MachineOperand.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetOpcodes.h"
|
|
|
|
#include "llvm/CodeGen/TargetSubtargetInfo.h"
|
2017-08-04 06:12:30 +08:00
|
|
|
#include "llvm/IR/DebugLoc.h"
|
|
|
|
#include "llvm/MC/MCInstrDesc.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include <cassert>
|
2011-06-29 04:07:07 +08:00
|
|
|
|
2014-04-22 10:03:14 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2013-11-19 08:57:56 +08:00
|
|
|
#define GET_INSTRINFO_CTOR_DTOR
|
2007-06-06 15:42:06 +08:00
|
|
|
#include "MipsGenInstrInfo.inc"
|
|
|
|
|
2013-11-19 08:57:56 +08:00
|
|
|
// Pin the vtable to this file.
|
|
|
|
void MipsInstrInfo::anchor() {}
|
|
|
|
|
2014-07-19 07:25:00 +08:00
|
|
|
MipsInstrInfo::MipsInstrInfo(const MipsSubtarget &STI, unsigned UncondBr)
|
|
|
|
: MipsGenInstrInfo(Mips::ADJCALLSTACKDOWN, Mips::ADJCALLSTACKUP),
|
|
|
|
Subtarget(STI), UncondBrOpc(UncondBr) {}
|
2011-07-08 07:56:50 +08:00
|
|
|
|
2014-07-19 07:25:00 +08:00
|
|
|
const MipsInstrInfo *MipsInstrInfo::create(MipsSubtarget &STI) {
|
|
|
|
if (STI.inMips16Mode())
|
2017-08-04 06:12:30 +08:00
|
|
|
return createMips16InstrInfo(STI);
|
2012-08-03 02:21:47 +08:00
|
|
|
|
2017-08-04 06:12:30 +08:00
|
|
|
return createMipsSEInstrInfo(STI);
|
2012-08-03 02:21:47 +08:00
|
|
|
}
|
|
|
|
|
2012-08-01 05:49:49 +08:00
|
|
|
bool MipsInstrInfo::isZeroImm(const MachineOperand &op) const {
|
2008-10-03 23:45:36 +08:00
|
|
|
return op.isImm() && op.getImm() == 0;
|
2007-06-06 15:42:06 +08:00
|
|
|
}
|
|
|
|
|
2007-08-18 09:56:48 +08:00
|
|
|
/// insertNoop - If data hazard condition is found insert the target nop
|
|
|
|
/// instruction.
|
2016-03-29 21:02:19 +08:00
|
|
|
// FIXME: This appears to be dead code.
|
2007-08-18 09:56:48 +08:00
|
|
|
void MipsInstrInfo::
|
2011-03-05 01:51:39 +08:00
|
|
|
insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const
|
2007-08-18 09:56:48 +08:00
|
|
|
{
|
2010-04-03 04:16:16 +08:00
|
|
|
DebugLoc DL;
|
2009-02-12 08:02:55 +08:00
|
|
|
BuildMI(MBB, MI, DL, get(Mips::NOP));
|
2007-08-18 09:56:48 +08:00
|
|
|
}
|
|
|
|
|
2016-07-16 02:26:59 +08:00
|
|
|
MachineMemOperand *
|
|
|
|
MipsInstrInfo::GetMemOperand(MachineBasicBlock &MBB, int FI,
|
|
|
|
MachineMemOperand::Flags Flags) const {
|
2011-12-24 11:11:18 +08:00
|
|
|
MachineFunction &MF = *MBB.getParent();
|
2016-07-29 02:40:00 +08:00
|
|
|
MachineFrameInfo &MFI = MF.getFrameInfo();
|
2011-12-24 11:11:18 +08:00
|
|
|
unsigned Align = MFI.getObjectAlignment(FI);
|
2012-02-28 15:46:26 +08:00
|
|
|
|
2015-08-12 07:09:45 +08:00
|
|
|
return MF.getMachineMemOperand(MachinePointerInfo::getFixedStack(MF, FI),
|
2016-07-16 02:26:59 +08:00
|
|
|
Flags, MFI.getObjectSize(FI), Align);
|
2011-12-24 11:11:18 +08:00
|
|
|
}
|
|
|
|
|
2011-04-16 05:51:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-08-18 09:56:48 +08:00
|
|
|
// Branch Analysis
|
2011-04-16 05:51:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-08-18 09:56:48 +08:00
|
|
|
|
2012-08-01 05:49:49 +08:00
|
|
|
void MipsInstrInfo::AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc,
|
|
|
|
MachineBasicBlock *&BB,
|
|
|
|
SmallVectorImpl<MachineOperand> &Cond) const {
|
2013-05-14 01:43:19 +08:00
|
|
|
assert(getAnalyzableBrOpc(Opc) && "Not an analyzable branch");
|
2011-04-02 01:39:08 +08:00
|
|
|
int NumOp = Inst->getNumExplicitOperands();
|
2012-02-28 15:46:26 +08:00
|
|
|
|
2011-04-02 01:39:08 +08:00
|
|
|
// for both int and fp branches, the last explicit operand is the
|
|
|
|
// MBB.
|
|
|
|
BB = Inst->getOperand(NumOp-1).getMBB();
|
|
|
|
Cond.push_back(MachineOperand::CreateImm(Opc));
|
|
|
|
|
2017-08-04 06:12:30 +08:00
|
|
|
for (int i = 0; i < NumOp-1; i++)
|
2011-04-02 01:39:08 +08:00
|
|
|
Cond.push_back(Inst->getOperand(i));
|
2007-08-18 09:56:48 +08:00
|
|
|
}
|
|
|
|
|
2016-07-15 22:41:04 +08:00
|
|
|
bool MipsInstrInfo::analyzeBranch(MachineBasicBlock &MBB,
|
2007-08-18 09:56:48 +08:00
|
|
|
MachineBasicBlock *&TBB,
|
|
|
|
MachineBasicBlock *&FBB,
|
2009-02-09 15:14:22 +08:00
|
|
|
SmallVectorImpl<MachineOperand> &Cond,
|
2013-03-01 09:10:17 +08:00
|
|
|
bool AllowModify) const {
|
|
|
|
SmallVector<MachineInstr*, 2> BranchInstrs;
|
2016-07-15 22:41:04 +08:00
|
|
|
BranchType BT = analyzeBranch(MBB, TBB, FBB, Cond, AllowModify, BranchInstrs);
|
2011-03-05 01:51:39 +08:00
|
|
|
|
2013-03-01 09:10:17 +08:00
|
|
|
return (BT == BT_None) || (BT == BT_Indirect);
|
2012-02-28 15:46:26 +08:00
|
|
|
}
|
|
|
|
|
2016-06-12 23:39:02 +08:00
|
|
|
void MipsInstrInfo::BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
|
|
|
|
const DebugLoc &DL,
|
|
|
|
ArrayRef<MachineOperand> Cond) const {
|
2011-04-02 01:39:08 +08:00
|
|
|
unsigned Opc = Cond[0].getImm();
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = get(Opc);
|
|
|
|
MachineInstrBuilder MIB = BuildMI(&MBB, DL, MCID);
|
2011-03-05 01:51:39 +08:00
|
|
|
|
2012-09-14 01:12:37 +08:00
|
|
|
for (unsigned i = 1; i < Cond.size(); ++i) {
|
2017-06-13 22:11:29 +08:00
|
|
|
assert((Cond[i].isImm() || Cond[i].isReg()) &&
|
|
|
|
"Cannot copy operand for conditional branch!");
|
|
|
|
MIB.add(Cond[i]);
|
2012-09-14 01:12:37 +08:00
|
|
|
}
|
2011-04-02 01:39:08 +08:00
|
|
|
MIB.addMBB(TBB);
|
2007-08-18 09:56:48 +08:00
|
|
|
}
|
|
|
|
|
2016-09-15 01:24:15 +08:00
|
|
|
unsigned MipsInstrInfo::insertBranch(MachineBasicBlock &MBB,
|
2016-06-12 23:39:02 +08:00
|
|
|
MachineBasicBlock *TBB,
|
|
|
|
MachineBasicBlock *FBB,
|
|
|
|
ArrayRef<MachineOperand> Cond,
|
2016-09-15 01:23:48 +08:00
|
|
|
const DebugLoc &DL,
|
|
|
|
int *BytesAdded) const {
|
2007-08-18 09:56:48 +08:00
|
|
|
// Shouldn't be a fall through.
|
2016-09-15 01:24:15 +08:00
|
|
|
assert(TBB && "insertBranch must not be told to insert a fallthrough");
|
2016-09-15 01:23:48 +08:00
|
|
|
assert(!BytesAdded && "code size not handled");
|
2007-08-18 09:56:48 +08:00
|
|
|
|
2011-04-02 01:39:08 +08:00
|
|
|
// # of condition operands:
|
|
|
|
// Unconditional branches: 0
|
|
|
|
// Floating point branches: 1 (opc)
|
|
|
|
// Int BranchZero: 2 (opc, reg)
|
|
|
|
// Int Branch: 3 (opc, reg0, reg1)
|
|
|
|
assert((Cond.size() <= 3) &&
|
|
|
|
"# of Mips branch conditions must be <= 3!");
|
2011-03-05 01:51:39 +08:00
|
|
|
|
2007-08-18 09:56:48 +08:00
|
|
|
// Two-way Conditional branch.
|
2011-04-02 01:39:08 +08:00
|
|
|
if (FBB) {
|
|
|
|
BuildCondBr(MBB, TBB, DL, Cond);
|
2011-12-13 06:39:35 +08:00
|
|
|
BuildMI(&MBB, DL, get(UncondBrOpc)).addMBB(FBB);
|
2011-04-02 01:39:08 +08:00
|
|
|
return 2;
|
|
|
|
}
|
2007-08-18 09:56:48 +08:00
|
|
|
|
2011-04-02 01:39:08 +08:00
|
|
|
// One way branch.
|
|
|
|
// Unconditional branch.
|
|
|
|
if (Cond.empty())
|
2011-12-13 06:39:35 +08:00
|
|
|
BuildMI(&MBB, DL, get(UncondBrOpc)).addMBB(TBB);
|
2011-04-02 01:39:08 +08:00
|
|
|
else // Conditional branch.
|
|
|
|
BuildCondBr(MBB, TBB, DL, Cond);
|
|
|
|
return 1;
|
2007-06-06 15:42:06 +08:00
|
|
|
}
|
2007-08-18 09:56:48 +08:00
|
|
|
|
2016-09-15 04:43:16 +08:00
|
|
|
unsigned MipsInstrInfo::removeBranch(MachineBasicBlock &MBB,
|
2016-09-15 01:23:48 +08:00
|
|
|
int *BytesRemoved) const {
|
|
|
|
assert(!BytesRemoved && "code size not handled");
|
|
|
|
|
2011-04-02 01:39:08 +08:00
|
|
|
MachineBasicBlock::reverse_iterator I = MBB.rbegin(), REnd = MBB.rend();
|
2017-10-26 18:58:36 +08:00
|
|
|
unsigned removed = 0;
|
2011-03-05 01:51:39 +08:00
|
|
|
|
2011-04-02 01:39:08 +08:00
|
|
|
// Up to 2 branches are removed.
|
|
|
|
// Note that indirect branches are not removed.
|
2017-10-26 18:58:36 +08:00
|
|
|
while (I != REnd && removed < 2) {
|
|
|
|
// Skip past debug instructions.
|
2018-05-09 10:42:00 +08:00
|
|
|
if (I->isDebugInstr()) {
|
2017-10-26 18:58:36 +08:00
|
|
|
++I;
|
|
|
|
continue;
|
|
|
|
}
|
2013-05-14 01:43:19 +08:00
|
|
|
if (!getAnalyzableBrOpc(I->getOpcode()))
|
2011-04-02 01:39:08 +08:00
|
|
|
break;
|
2017-10-26 18:58:36 +08:00
|
|
|
// Remove the branch.
|
|
|
|
I->eraseFromParent();
|
|
|
|
I = MBB.rbegin();
|
|
|
|
++removed;
|
|
|
|
}
|
2011-03-05 01:51:39 +08:00
|
|
|
|
2011-04-02 01:39:08 +08:00
|
|
|
return removed;
|
2007-08-18 09:56:48 +08:00
|
|
|
}
|
|
|
|
|
2016-09-15 04:43:16 +08:00
|
|
|
/// reverseBranchCondition - Return the inverse opcode of the
|
2007-08-18 09:56:48 +08:00
|
|
|
/// specified Branch instruction.
|
2016-09-15 04:43:16 +08:00
|
|
|
bool MipsInstrInfo::reverseBranchCondition(
|
2014-07-19 04:35:49 +08:00
|
|
|
SmallVectorImpl<MachineOperand> &Cond) const {
|
2011-04-02 01:39:08 +08:00
|
|
|
assert( (Cond.size() && Cond.size() <= 3) &&
|
2007-08-18 09:56:48 +08:00
|
|
|
"Invalid Mips branch condition!");
|
2013-05-14 01:43:19 +08:00
|
|
|
Cond[0].setImm(getOppositeBranchOpc(Cond[0].getImm()));
|
2007-08-18 09:56:48 +08:00
|
|
|
return false;
|
|
|
|
}
|
2009-06-04 04:30:14 +08:00
|
|
|
|
2016-07-15 22:41:04 +08:00
|
|
|
MipsInstrInfo::BranchType MipsInstrInfo::analyzeBranch(
|
2014-07-19 04:35:49 +08:00
|
|
|
MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB,
|
|
|
|
SmallVectorImpl<MachineOperand> &Cond, bool AllowModify,
|
|
|
|
SmallVectorImpl<MachineInstr *> &BranchInstrs) const {
|
2013-03-01 09:10:17 +08:00
|
|
|
MachineBasicBlock::reverse_iterator I = MBB.rbegin(), REnd = MBB.rend();
|
|
|
|
|
|
|
|
// Skip all the debug instructions.
|
2018-05-09 10:42:00 +08:00
|
|
|
while (I != REnd && I->isDebugInstr())
|
2013-03-01 09:10:17 +08:00
|
|
|
++I;
|
|
|
|
|
2016-02-23 10:46:52 +08:00
|
|
|
if (I == REnd || !isUnpredicatedTerminator(*I)) {
|
2013-03-01 09:10:17 +08:00
|
|
|
// This block ends with no branches (it just falls through to its succ).
|
|
|
|
// Leave TBB/FBB null.
|
2014-04-25 13:30:21 +08:00
|
|
|
TBB = FBB = nullptr;
|
2013-03-01 09:10:17 +08:00
|
|
|
return BT_NoBranch;
|
|
|
|
}
|
|
|
|
|
|
|
|
MachineInstr *LastInst = &*I;
|
|
|
|
unsigned LastOpc = LastInst->getOpcode();
|
|
|
|
BranchInstrs.push_back(LastInst);
|
|
|
|
|
|
|
|
// Not an analyzable branch (e.g., indirect jump).
|
2013-05-14 01:43:19 +08:00
|
|
|
if (!getAnalyzableBrOpc(LastOpc))
|
2013-03-01 09:10:17 +08:00
|
|
|
return LastInst->isIndirectBranch() ? BT_Indirect : BT_None;
|
|
|
|
|
|
|
|
// Get the second to last instruction in the block.
|
|
|
|
unsigned SecondLastOpc = 0;
|
2014-04-25 13:30:21 +08:00
|
|
|
MachineInstr *SecondLastInst = nullptr;
|
2013-03-01 09:10:17 +08:00
|
|
|
|
2017-10-18 22:35:29 +08:00
|
|
|
// Skip past any debug instruction to see if the second last actual
|
|
|
|
// is a branch.
|
|
|
|
++I;
|
2018-05-09 10:42:00 +08:00
|
|
|
while (I != REnd && I->isDebugInstr())
|
2017-10-18 22:35:29 +08:00
|
|
|
++I;
|
|
|
|
|
|
|
|
if (I != REnd) {
|
2013-03-01 09:10:17 +08:00
|
|
|
SecondLastInst = &*I;
|
2013-05-14 01:43:19 +08:00
|
|
|
SecondLastOpc = getAnalyzableBrOpc(SecondLastInst->getOpcode());
|
2013-03-01 09:10:17 +08:00
|
|
|
|
|
|
|
// Not an analyzable branch (must be an indirect jump).
|
2016-02-23 10:46:52 +08:00
|
|
|
if (isUnpredicatedTerminator(*SecondLastInst) && !SecondLastOpc)
|
2013-03-01 09:10:17 +08:00
|
|
|
return BT_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is only one terminator instruction, process it.
|
|
|
|
if (!SecondLastOpc) {
|
2013-10-01 20:53:00 +08:00
|
|
|
// Unconditional branch.
|
2016-05-06 21:23:51 +08:00
|
|
|
if (LastInst->isUnconditionalBranch()) {
|
2013-03-01 09:10:17 +08:00
|
|
|
TBB = LastInst->getOperand(0).getMBB();
|
|
|
|
return BT_Uncond;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Conditional branch
|
|
|
|
AnalyzeCondBr(LastInst, LastOpc, TBB, Cond);
|
|
|
|
return BT_Cond;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we reached here, there are two branches.
|
|
|
|
// If there are three terminators, we don't know what sort of block this is.
|
2016-02-23 10:46:52 +08:00
|
|
|
if (++I != REnd && isUnpredicatedTerminator(*I))
|
2013-03-01 09:10:17 +08:00
|
|
|
return BT_None;
|
|
|
|
|
2013-03-01 09:22:26 +08:00
|
|
|
BranchInstrs.insert(BranchInstrs.begin(), SecondLastInst);
|
|
|
|
|
2013-03-01 09:10:17 +08:00
|
|
|
// If second to last instruction is an unconditional branch,
|
|
|
|
// analyze it and remove the last instruction.
|
2016-05-06 21:23:51 +08:00
|
|
|
if (SecondLastInst->isUnconditionalBranch()) {
|
2013-03-01 09:10:17 +08:00
|
|
|
// Return if the last instruction cannot be removed.
|
|
|
|
if (!AllowModify)
|
|
|
|
return BT_None;
|
|
|
|
|
|
|
|
TBB = SecondLastInst->getOperand(0).getMBB();
|
|
|
|
LastInst->eraseFromParent();
|
|
|
|
BranchInstrs.pop_back();
|
|
|
|
return BT_Uncond;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Conditional branch followed by an unconditional branch.
|
|
|
|
// The last one must be unconditional.
|
2016-05-06 21:23:51 +08:00
|
|
|
if (!LastInst->isUnconditionalBranch())
|
2013-03-01 09:10:17 +08:00
|
|
|
return BT_None;
|
|
|
|
|
|
|
|
AnalyzeCondBr(SecondLastInst, SecondLastOpc, TBB, Cond);
|
|
|
|
FBB = LastInst->getOperand(0).getMBB();
|
|
|
|
|
|
|
|
return BT_CondUncond;
|
|
|
|
}
|
|
|
|
|
2018-05-16 18:03:05 +08:00
|
|
|
bool MipsInstrInfo::isBranchOffsetInRange(unsigned BranchOpc, int64_t BrOffset) const {
|
|
|
|
switch (BranchOpc) {
|
|
|
|
case Mips::B:
|
|
|
|
case Mips::BAL:
|
|
|
|
case Mips::BC1F:
|
|
|
|
case Mips::BC1FL:
|
|
|
|
case Mips::BC1T:
|
|
|
|
case Mips::BC1TL:
|
|
|
|
case Mips::BEQ: case Mips::BEQ64:
|
|
|
|
case Mips::BEQL:
|
|
|
|
case Mips::BGEZ: case Mips::BGEZ64:
|
|
|
|
case Mips::BGEZL:
|
|
|
|
case Mips::BGEZAL:
|
|
|
|
case Mips::BGEZALL:
|
|
|
|
case Mips::BGTZ: case Mips::BGTZ64:
|
|
|
|
case Mips::BGTZL:
|
|
|
|
case Mips::BLEZ: case Mips::BLEZ64:
|
|
|
|
case Mips::BLEZL:
|
|
|
|
case Mips::BLTZ: case Mips::BLTZ64:
|
|
|
|
case Mips::BLTZL:
|
|
|
|
case Mips::BLTZAL:
|
|
|
|
case Mips::BLTZALL:
|
|
|
|
case Mips::BNE: case Mips::BNE64:
|
|
|
|
case Mips::BNEL:
|
|
|
|
return isInt<18>(BrOffset);
|
|
|
|
|
|
|
|
// microMIPSr3 branches
|
|
|
|
case Mips::B_MM:
|
|
|
|
case Mips::BC1F_MM:
|
|
|
|
case Mips::BC1T_MM:
|
|
|
|
case Mips::BEQ_MM:
|
|
|
|
case Mips::BGEZ_MM:
|
|
|
|
case Mips::BGEZAL_MM:
|
|
|
|
case Mips::BGTZ_MM:
|
|
|
|
case Mips::BLEZ_MM:
|
|
|
|
case Mips::BLTZ_MM:
|
|
|
|
case Mips::BLTZAL_MM:
|
|
|
|
case Mips::BNE_MM:
|
|
|
|
case Mips::BEQZC_MM:
|
|
|
|
case Mips::BNEZC_MM:
|
|
|
|
return isInt<17>(BrOffset);
|
|
|
|
|
|
|
|
// microMIPSR3 short branches.
|
|
|
|
case Mips::B16_MM:
|
|
|
|
return isInt<11>(BrOffset);
|
|
|
|
|
|
|
|
case Mips::BEQZ16_MM:
|
|
|
|
case Mips::BNEZ16_MM:
|
|
|
|
return isInt<8>(BrOffset);
|
|
|
|
|
|
|
|
// MIPSR6 branches.
|
|
|
|
case Mips::BALC:
|
|
|
|
case Mips::BC:
|
|
|
|
return isInt<28>(BrOffset);
|
|
|
|
|
|
|
|
case Mips::BC1EQZ:
|
|
|
|
case Mips::BC1NEZ:
|
|
|
|
case Mips::BC2EQZ:
|
|
|
|
case Mips::BC2NEZ:
|
|
|
|
case Mips::BEQC: case Mips::BEQC64:
|
|
|
|
case Mips::BNEC: case Mips::BNEC64:
|
|
|
|
case Mips::BGEC: case Mips::BGEC64:
|
|
|
|
case Mips::BGEUC: case Mips::BGEUC64:
|
|
|
|
case Mips::BGEZC: case Mips::BGEZC64:
|
|
|
|
case Mips::BGTZC: case Mips::BGTZC64:
|
|
|
|
case Mips::BLEZC: case Mips::BLEZC64:
|
|
|
|
case Mips::BLTC: case Mips::BLTC64:
|
|
|
|
case Mips::BLTUC: case Mips::BLTUC64:
|
|
|
|
case Mips::BLTZC: case Mips::BLTZC64:
|
|
|
|
case Mips::BNVC:
|
|
|
|
case Mips::BOVC:
|
|
|
|
case Mips::BGEZALC:
|
|
|
|
case Mips::BEQZALC:
|
|
|
|
case Mips::BGTZALC:
|
|
|
|
case Mips::BLEZALC:
|
|
|
|
case Mips::BLTZALC:
|
|
|
|
case Mips::BNEZALC:
|
|
|
|
return isInt<18>(BrOffset);
|
|
|
|
|
|
|
|
case Mips::BEQZC: case Mips::BEQZC64:
|
|
|
|
case Mips::BNEZC: case Mips::BNEZC64:
|
|
|
|
return isInt<23>(BrOffset);
|
|
|
|
|
|
|
|
// microMIPSR6 branches
|
|
|
|
case Mips::BC16_MMR6:
|
|
|
|
return isInt<11>(BrOffset);
|
|
|
|
|
|
|
|
case Mips::BEQZC16_MMR6:
|
|
|
|
case Mips::BNEZC16_MMR6:
|
|
|
|
return isInt<8>(BrOffset);
|
|
|
|
|
|
|
|
case Mips::BALC_MMR6:
|
|
|
|
case Mips::BC_MMR6:
|
|
|
|
return isInt<27>(BrOffset);
|
|
|
|
|
|
|
|
case Mips::BC1EQZC_MMR6:
|
|
|
|
case Mips::BC1NEZC_MMR6:
|
|
|
|
case Mips::BC2EQZC_MMR6:
|
|
|
|
case Mips::BC2NEZC_MMR6:
|
|
|
|
case Mips::BGEZALC_MMR6:
|
|
|
|
case Mips::BEQZALC_MMR6:
|
|
|
|
case Mips::BGTZALC_MMR6:
|
|
|
|
case Mips::BLEZALC_MMR6:
|
|
|
|
case Mips::BLTZALC_MMR6:
|
|
|
|
case Mips::BNEZALC_MMR6:
|
|
|
|
case Mips::BNVC_MMR6:
|
|
|
|
case Mips::BOVC_MMR6:
|
|
|
|
return isInt<17>(BrOffset);
|
|
|
|
|
|
|
|
case Mips::BEQC_MMR6:
|
|
|
|
case Mips::BNEC_MMR6:
|
|
|
|
case Mips::BGEC_MMR6:
|
|
|
|
case Mips::BGEUC_MMR6:
|
|
|
|
case Mips::BGEZC_MMR6:
|
|
|
|
case Mips::BGTZC_MMR6:
|
|
|
|
case Mips::BLEZC_MMR6:
|
|
|
|
case Mips::BLTC_MMR6:
|
|
|
|
case Mips::BLTUC_MMR6:
|
|
|
|
case Mips::BLTZC_MMR6:
|
|
|
|
return isInt<18>(BrOffset);
|
|
|
|
|
|
|
|
case Mips::BEQZC_MMR6:
|
|
|
|
case Mips::BNEZC_MMR6:
|
|
|
|
return isInt<23>(BrOffset);
|
|
|
|
|
|
|
|
// DSP branches.
|
|
|
|
case Mips::BPOSGE32:
|
|
|
|
return isInt<18>(BrOffset);
|
|
|
|
case Mips::BPOSGE32_MM:
|
|
|
|
case Mips::BPOSGE32C_MMR3:
|
|
|
|
return isInt<17>(BrOffset);
|
|
|
|
|
|
|
|
// cnMIPS branches.
|
|
|
|
case Mips::BBIT0:
|
|
|
|
case Mips::BBIT032:
|
|
|
|
case Mips::BBIT1:
|
|
|
|
case Mips::BBIT132:
|
|
|
|
return isInt<18>(BrOffset);
|
|
|
|
|
|
|
|
// MSA branches.
|
|
|
|
case Mips::BZ_B:
|
|
|
|
case Mips::BZ_H:
|
|
|
|
case Mips::BZ_W:
|
|
|
|
case Mips::BZ_D:
|
|
|
|
case Mips::BZ_V:
|
|
|
|
case Mips::BNZ_B:
|
|
|
|
case Mips::BNZ_H:
|
|
|
|
case Mips::BNZ_W:
|
|
|
|
case Mips::BNZ_D:
|
|
|
|
case Mips::BNZ_V:
|
|
|
|
return isInt<18>(BrOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("Unknown branch instruction!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-15 00:24:05 +08:00
|
|
|
/// Return the corresponding compact (no delay slot) form of a branch.
|
|
|
|
unsigned MipsInstrInfo::getEquivalentCompactForm(
|
|
|
|
const MachineBasicBlock::iterator I) const {
|
|
|
|
unsigned Opcode = I->getOpcode();
|
2016-04-05 20:50:29 +08:00
|
|
|
bool canUseShortMicroMipsCTI = false;
|
2016-03-15 00:24:05 +08:00
|
|
|
|
2016-04-05 20:50:29 +08:00
|
|
|
if (Subtarget.inMicroMipsMode()) {
|
|
|
|
switch (Opcode) {
|
|
|
|
case Mips::BNE:
|
2016-07-22 15:18:33 +08:00
|
|
|
case Mips::BNE_MM:
|
2016-04-05 20:50:29 +08:00
|
|
|
case Mips::BEQ:
|
2016-07-22 15:18:33 +08:00
|
|
|
case Mips::BEQ_MM:
|
2016-04-05 20:50:29 +08:00
|
|
|
// microMIPS has NE,EQ branches that do not have delay slots provided one
|
|
|
|
// of the operands is zero.
|
|
|
|
if (I->getOperand(1).getReg() == Subtarget.getABI().GetZeroReg())
|
|
|
|
canUseShortMicroMipsCTI = true;
|
|
|
|
break;
|
|
|
|
// For microMIPS the PseudoReturn and PseudoIndirectBranch are always
|
|
|
|
// expanded to JR_MM, so they can be replaced with JRC16_MM.
|
|
|
|
case Mips::JR:
|
|
|
|
case Mips::PseudoReturn:
|
|
|
|
case Mips::PseudoIndirectBranch:
|
|
|
|
canUseShortMicroMipsCTI = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-18 18:38:01 +08:00
|
|
|
// MIPSR6 forbids both operands being the zero register.
|
|
|
|
if (Subtarget.hasMips32r6() && (I->getNumOperands() > 1) &&
|
|
|
|
(I->getOperand(0).isReg() &&
|
|
|
|
(I->getOperand(0).getReg() == Mips::ZERO ||
|
|
|
|
I->getOperand(0).getReg() == Mips::ZERO_64)) &&
|
|
|
|
(I->getOperand(1).isReg() &&
|
|
|
|
(I->getOperand(1).getReg() == Mips::ZERO ||
|
|
|
|
I->getOperand(1).getReg() == Mips::ZERO_64)))
|
|
|
|
return 0;
|
|
|
|
|
2016-04-05 20:50:29 +08:00
|
|
|
if (Subtarget.hasMips32r6() || canUseShortMicroMipsCTI) {
|
2016-03-15 00:24:05 +08:00
|
|
|
switch (Opcode) {
|
|
|
|
case Mips::B:
|
|
|
|
return Mips::BC;
|
|
|
|
case Mips::BAL:
|
|
|
|
return Mips::BALC;
|
|
|
|
case Mips::BEQ:
|
2016-07-22 15:18:33 +08:00
|
|
|
case Mips::BEQ_MM:
|
2016-04-05 20:50:29 +08:00
|
|
|
if (canUseShortMicroMipsCTI)
|
2016-03-15 00:24:05 +08:00
|
|
|
return Mips::BEQZC_MM;
|
2016-05-31 17:54:55 +08:00
|
|
|
else if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
|
|
|
|
return 0;
|
|
|
|
return Mips::BEQC;
|
2016-03-15 00:24:05 +08:00
|
|
|
case Mips::BNE:
|
2016-07-22 15:18:33 +08:00
|
|
|
case Mips::BNE_MM:
|
2016-04-05 20:50:29 +08:00
|
|
|
if (canUseShortMicroMipsCTI)
|
2016-03-15 00:24:05 +08:00
|
|
|
return Mips::BNEZC_MM;
|
2016-05-31 17:54:55 +08:00
|
|
|
else if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
|
|
|
|
return 0;
|
|
|
|
return Mips::BNEC;
|
2016-03-15 00:24:05 +08:00
|
|
|
case Mips::BGE:
|
2016-05-18 18:38:01 +08:00
|
|
|
if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
|
|
|
|
return 0;
|
2016-03-15 00:24:05 +08:00
|
|
|
return Mips::BGEC;
|
|
|
|
case Mips::BGEU:
|
2016-05-18 18:38:01 +08:00
|
|
|
if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
|
|
|
|
return 0;
|
2016-03-15 00:24:05 +08:00
|
|
|
return Mips::BGEUC;
|
|
|
|
case Mips::BGEZ:
|
|
|
|
return Mips::BGEZC;
|
|
|
|
case Mips::BGTZ:
|
|
|
|
return Mips::BGTZC;
|
|
|
|
case Mips::BLEZ:
|
|
|
|
return Mips::BLEZC;
|
|
|
|
case Mips::BLT:
|
2016-05-18 18:38:01 +08:00
|
|
|
if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
|
|
|
|
return 0;
|
2016-03-15 00:24:05 +08:00
|
|
|
return Mips::BLTC;
|
|
|
|
case Mips::BLTU:
|
2016-05-18 18:38:01 +08:00
|
|
|
if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
|
|
|
|
return 0;
|
2016-03-15 00:24:05 +08:00
|
|
|
return Mips::BLTUC;
|
|
|
|
case Mips::BLTZ:
|
|
|
|
return Mips::BLTZC;
|
2016-07-26 18:25:07 +08:00
|
|
|
case Mips::BEQ64:
|
|
|
|
if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
|
|
|
|
return 0;
|
|
|
|
return Mips::BEQC64;
|
|
|
|
case Mips::BNE64:
|
|
|
|
if (I->getOperand(0).getReg() == I->getOperand(1).getReg())
|
|
|
|
return 0;
|
|
|
|
return Mips::BNEC64;
|
|
|
|
case Mips::BGTZ64:
|
|
|
|
return Mips::BGTZC64;
|
|
|
|
case Mips::BGEZ64:
|
|
|
|
return Mips::BGEZC64;
|
|
|
|
case Mips::BLTZ64:
|
|
|
|
return Mips::BLTZC64;
|
|
|
|
case Mips::BLEZ64:
|
|
|
|
return Mips::BLEZC64;
|
2016-04-05 20:50:29 +08:00
|
|
|
// For MIPSR6, the instruction 'jic' can be used for these cases. Some
|
|
|
|
// tools will accept 'jrc reg' as an alias for 'jic 0, $reg'.
|
|
|
|
case Mips::JR:
|
2018-02-21 08:06:53 +08:00
|
|
|
case Mips::PseudoIndirectBranchR6:
|
2016-04-05 20:50:29 +08:00
|
|
|
case Mips::PseudoReturn:
|
2018-02-21 08:06:53 +08:00
|
|
|
case Mips::TAILCALLR6REG:
|
2016-04-05 20:50:29 +08:00
|
|
|
if (canUseShortMicroMipsCTI)
|
|
|
|
return Mips::JRC16_MM;
|
|
|
|
return Mips::JIC;
|
|
|
|
case Mips::JALRPseudo:
|
|
|
|
return Mips::JIALC;
|
|
|
|
case Mips::JR64:
|
2018-02-21 08:06:53 +08:00
|
|
|
case Mips::PseudoIndirectBranch64R6:
|
2016-04-05 20:50:29 +08:00
|
|
|
case Mips::PseudoReturn64:
|
2018-02-21 08:06:53 +08:00
|
|
|
case Mips::TAILCALL64R6REG:
|
2016-04-05 20:50:29 +08:00
|
|
|
return Mips::JIC64;
|
|
|
|
case Mips::JALR64Pseudo:
|
|
|
|
return Mips::JIALC64;
|
2016-05-18 18:38:01 +08:00
|
|
|
default:
|
2016-03-15 00:24:05 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Predicate for distingushing between control transfer instructions and all
|
|
|
|
/// other instructions for handling forbidden slots. Consider inline assembly
|
|
|
|
/// as unsafe as well.
|
|
|
|
bool MipsInstrInfo::SafeInForbiddenSlot(const MachineInstr &MI) const {
|
|
|
|
if (MI.isInlineAsm())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (MI.getDesc().TSFlags & MipsII::IsCTI) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Predicate for distingushing instructions that have forbidden slots.
|
|
|
|
bool MipsInstrInfo::HasForbiddenSlot(const MachineInstr &MI) const {
|
|
|
|
return (MI.getDesc().TSFlags & MipsII::HasForbiddenSlot) != 0;
|
|
|
|
}
|
|
|
|
|
2012-06-14 09:16:45 +08:00
|
|
|
/// Return the number of bytes of code the specified instruction may be.
|
2016-07-29 00:32:22 +08:00
|
|
|
unsigned MipsInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
|
2016-07-16 07:09:47 +08:00
|
|
|
switch (MI.getOpcode()) {
|
2012-06-14 09:16:45 +08:00
|
|
|
default:
|
2016-07-16 07:09:47 +08:00
|
|
|
return MI.getDesc().getSize();
|
2012-06-14 09:16:45 +08:00
|
|
|
case TargetOpcode::INLINEASM: { // Inline Asm: Variable size.
|
2016-07-16 07:09:47 +08:00
|
|
|
const MachineFunction *MF = MI.getParent()->getParent();
|
|
|
|
const char *AsmStr = MI.getOperand(0).getSymbolName();
|
2012-06-14 09:16:45 +08:00
|
|
|
return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo());
|
|
|
|
}
|
2013-10-28 05:57:36 +08:00
|
|
|
case Mips::CONSTPOOL_ENTRY:
|
|
|
|
// If this machine instr is a constant pool entry, its size is recorded as
|
|
|
|
// operand #2.
|
2016-07-16 07:09:47 +08:00
|
|
|
return MI.getOperand(2).getImm();
|
2012-06-14 09:16:45 +08:00
|
|
|
}
|
|
|
|
}
|
2013-05-14 01:57:42 +08:00
|
|
|
|
|
|
|
MachineInstrBuilder
|
|
|
|
MipsInstrInfo::genInstrWithNewOpc(unsigned NewOpc,
|
|
|
|
MachineBasicBlock::iterator I) const {
|
|
|
|
MachineInstrBuilder MIB;
|
2016-03-15 00:24:05 +08:00
|
|
|
|
2016-07-26 18:25:07 +08:00
|
|
|
// Certain branches have two forms: e.g beq $1, $zero, dest vs beqz $1, dest
|
2016-03-15 00:24:05 +08:00
|
|
|
// Pick the zero form of the branch for readable assembly and for greater
|
|
|
|
// branch distance in non-microMIPS mode.
|
2016-08-17 01:16:11 +08:00
|
|
|
// Additional MIPSR6 does not permit the use of register $zero for compact
|
|
|
|
// branches.
|
2016-04-05 20:50:29 +08:00
|
|
|
// FIXME: Certain atomic sequences on mips64 generate 32bit references to
|
|
|
|
// Mips::ZERO, which is incorrect. This test should be updated to use
|
|
|
|
// Subtarget.getABI().GetZeroReg() when those atomic sequences and others
|
|
|
|
// are fixed.
|
2016-08-17 01:16:11 +08:00
|
|
|
int ZeroOperandPosition = -1;
|
|
|
|
bool BranchWithZeroOperand = false;
|
|
|
|
if (I->isBranch() && !I->isPseudo()) {
|
|
|
|
auto TRI = I->getParent()->getParent()->getSubtarget().getRegisterInfo();
|
|
|
|
ZeroOperandPosition = I->findRegisterUseOperandIdx(Mips::ZERO, false, TRI);
|
|
|
|
BranchWithZeroOperand = ZeroOperandPosition != -1;
|
|
|
|
}
|
2016-04-05 20:50:29 +08:00
|
|
|
|
|
|
|
if (BranchWithZeroOperand) {
|
2016-03-15 00:24:05 +08:00
|
|
|
switch (NewOpc) {
|
|
|
|
case Mips::BEQC:
|
|
|
|
NewOpc = Mips::BEQZC;
|
|
|
|
break;
|
|
|
|
case Mips::BNEC:
|
|
|
|
NewOpc = Mips::BNEZC;
|
|
|
|
break;
|
|
|
|
case Mips::BGEC:
|
|
|
|
NewOpc = Mips::BGEZC;
|
|
|
|
break;
|
|
|
|
case Mips::BLTC:
|
|
|
|
NewOpc = Mips::BLTZC;
|
|
|
|
break;
|
2016-07-26 18:25:07 +08:00
|
|
|
case Mips::BEQC64:
|
|
|
|
NewOpc = Mips::BEQZC64;
|
|
|
|
break;
|
|
|
|
case Mips::BNEC64:
|
|
|
|
NewOpc = Mips::BNEZC64;
|
|
|
|
break;
|
2016-03-15 00:24:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-14 01:57:42 +08:00
|
|
|
MIB = BuildMI(*I->getParent(), I, I->getDebugLoc(), get(NewOpc));
|
|
|
|
|
2016-04-05 20:50:29 +08:00
|
|
|
// For MIPSR6 JI*C requires an immediate 0 as an operand, JIALC(64) an
|
2017-12-07 18:40:31 +08:00
|
|
|
// immediate 0 as an operand and requires the removal of it's implicit-def %ra
|
2016-04-05 20:50:29 +08:00
|
|
|
// implicit operand as copying the implicit operations of the instructio we're
|
|
|
|
// looking at will give us the correct flags.
|
|
|
|
if (NewOpc == Mips::JIC || NewOpc == Mips::JIALC || NewOpc == Mips::JIC64 ||
|
|
|
|
NewOpc == Mips::JIALC64) {
|
|
|
|
|
|
|
|
if (NewOpc == Mips::JIALC || NewOpc == Mips::JIALC64)
|
|
|
|
MIB->RemoveOperand(0);
|
|
|
|
|
|
|
|
for (unsigned J = 0, E = I->getDesc().getNumOperands(); J < E; ++J) {
|
2017-01-13 17:58:52 +08:00
|
|
|
MIB.add(I->getOperand(J));
|
2016-04-05 20:50:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MIB.addImm(0);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
for (unsigned J = 0, E = I->getDesc().getNumOperands(); J < E; ++J) {
|
2016-08-17 01:16:11 +08:00
|
|
|
if (BranchWithZeroOperand && (unsigned)ZeroOperandPosition == J)
|
|
|
|
continue;
|
|
|
|
|
2017-01-13 17:58:52 +08:00
|
|
|
MIB.add(I->getOperand(J));
|
2016-04-05 20:50:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MIB.copyImplicitOps(*I);
|
2013-05-14 01:57:42 +08:00
|
|
|
|
|
|
|
MIB.setMemRefs(I->memoperands_begin(), I->memoperands_end());
|
|
|
|
return MIB;
|
|
|
|
}
|
2017-03-31 22:31:55 +08:00
|
|
|
|
|
|
|
bool MipsInstrInfo::findCommutedOpIndices(MachineInstr &MI, unsigned &SrcOpIdx1,
|
|
|
|
unsigned &SrcOpIdx2) const {
|
|
|
|
assert(!MI.isBundle() &&
|
|
|
|
"TargetInstrInfo::findCommutedOpIndices() can't handle bundles");
|
|
|
|
|
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
|
|
|
if (!MCID.isCommutable())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (MI.getOpcode()) {
|
|
|
|
case Mips::DPADD_U_H:
|
|
|
|
case Mips::DPADD_U_W:
|
|
|
|
case Mips::DPADD_U_D:
|
|
|
|
case Mips::DPADD_S_H:
|
|
|
|
case Mips::DPADD_S_W:
|
2017-08-04 06:12:30 +08:00
|
|
|
case Mips::DPADD_S_D:
|
2017-03-31 22:31:55 +08:00
|
|
|
// The first operand is both input and output, so it should not commute
|
|
|
|
if (!fixCommutedOpIndices(SrcOpIdx1, SrcOpIdx2, 2, 3))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!MI.getOperand(SrcOpIdx1).isReg() || !MI.getOperand(SrcOpIdx2).isReg())
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return TargetInstrInfo::findCommutedOpIndices(MI, SrcOpIdx1, SrcOpIdx2);
|
|
|
|
}
|
[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
|
|
|
|
|
|
|
// ins, ext, dext*, dins have the following constraints:
|
2017-12-18 23:56:40 +08:00
|
|
|
// X <= pos < Y
|
|
|
|
// X < size <= Y
|
|
|
|
// X < pos+size <= Y
|
[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
|
|
|
//
|
2017-12-18 23:56:40 +08:00
|
|
|
// dinsm and dinsu have the following constraints:
|
|
|
|
// X <= pos < Y
|
|
|
|
// X <= size <= Y
|
|
|
|
// X < pos+size <= Y
|
|
|
|
//
|
|
|
|
// The callee of verifyInsExtInstruction however gives the bounds of
|
|
|
|
// dins[um] like the other (d)ins (d)ext(um) instructions, so that this
|
|
|
|
// function doesn't have to vary it's behaviour based on the instruction
|
|
|
|
// being checked.
|
[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
|
|
|
static bool verifyInsExtInstruction(const MachineInstr &MI, StringRef &ErrInfo,
|
|
|
|
const int64_t PosLow, const int64_t PosHigh,
|
|
|
|
const int64_t SizeLow,
|
|
|
|
const int64_t SizeHigh,
|
|
|
|
const int64_t BothLow,
|
|
|
|
const int64_t BothHigh) {
|
|
|
|
MachineOperand MOPos = MI.getOperand(2);
|
|
|
|
if (!MOPos.isImm()) {
|
|
|
|
ErrInfo = "Position is not an immediate!";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int64_t Pos = MOPos.getImm();
|
|
|
|
if (!((PosLow <= Pos) && (Pos < PosHigh))) {
|
|
|
|
ErrInfo = "Position operand is out of range!";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MachineOperand MOSize = MI.getOperand(3);
|
|
|
|
if (!MOSize.isImm()) {
|
|
|
|
ErrInfo = "Size operand is not an immediate!";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int64_t Size = MOSize.getImm();
|
|
|
|
if (!((SizeLow < Size) && (Size <= SizeHigh))) {
|
|
|
|
ErrInfo = "Size operand is out of range!";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!((BothLow < (Pos + Size)) && ((Pos + Size) <= BothHigh))) {
|
|
|
|
ErrInfo = "Position + Size is out of range!";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform target specific instruction verification.
|
|
|
|
bool MipsInstrInfo::verifyInstruction(const MachineInstr &MI,
|
|
|
|
StringRef &ErrInfo) const {
|
|
|
|
// Verify that ins and ext instructions are well formed.
|
|
|
|
switch (MI.getOpcode()) {
|
|
|
|
case Mips::EXT:
|
|
|
|
case Mips::EXT_MM:
|
|
|
|
case Mips::INS:
|
|
|
|
case Mips::INS_MM:
|
|
|
|
case Mips::DINS:
|
|
|
|
return verifyInsExtInstruction(MI, ErrInfo, 0, 32, 0, 32, 0, 32);
|
|
|
|
case Mips::DINSM:
|
2018-03-31 06:22:31 +08:00
|
|
|
// The ISA spec has a subtle difference between dinsm and dextm
|
2017-12-18 23:56:40 +08:00
|
|
|
// in that it says:
|
|
|
|
// 2 <= size <= 64 for 'dinsm' but 'dextm' has 32 < size <= 64.
|
|
|
|
// To make the bounds checks similar, the range 1 < size <= 64 is checked
|
|
|
|
// for 'dinsm'.
|
[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
|
|
|
return verifyInsExtInstruction(MI, ErrInfo, 0, 32, 1, 64, 32, 64);
|
|
|
|
case Mips::DINSU:
|
2017-12-18 23:56:40 +08:00
|
|
|
// The ISA spec has a subtle difference between dinsu and dextu in that
|
|
|
|
// the size range of dinsu is specified as 1 <= size <= 32 whereas size
|
|
|
|
// for dextu is 0 < size <= 32. The range checked for dinsu here is
|
|
|
|
// 0 < size <= 32, which is equivalent and similar to dextu.
|
|
|
|
return verifyInsExtInstruction(MI, ErrInfo, 32, 64, 0, 32, 32, 64);
|
[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
|
|
|
case Mips::DEXT:
|
|
|
|
return verifyInsExtInstruction(MI, ErrInfo, 0, 32, 0, 32, 0, 63);
|
|
|
|
case Mips::DEXTM:
|
|
|
|
return verifyInsExtInstruction(MI, ErrInfo, 0, 32, 32, 64, 32, 64);
|
|
|
|
case Mips::DEXTU:
|
|
|
|
return verifyInsExtInstruction(MI, ErrInfo, 32, 64, 0, 32, 32, 64);
|
2018-02-21 08:06:53 +08:00
|
|
|
case Mips::TAILCALLREG:
|
|
|
|
case Mips::PseudoIndirectBranch:
|
|
|
|
case Mips::JR:
|
|
|
|
case Mips::JR64:
|
|
|
|
case Mips::JALR:
|
|
|
|
case Mips::JALR64:
|
|
|
|
case Mips::JALRPseudo:
|
|
|
|
if (!Subtarget.useIndirectJumpsHazard())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
ErrInfo = "invalid instruction when using jump guards!";
|
|
|
|
return false;
|
[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
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-11 19:11:35 +08:00
|
|
|
std::pair<unsigned, unsigned>
|
|
|
|
MipsInstrInfo::decomposeMachineOperandsTargetFlags(unsigned TF) const {
|
|
|
|
return std::make_pair(TF, 0u);
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayRef<std::pair<unsigned, const char*>>
|
|
|
|
MipsInstrInfo::getSerializableDirectMachineOperandTargetFlags() const {
|
|
|
|
using namespace MipsII;
|
|
|
|
|
|
|
|
static const std::pair<unsigned, const char*> Flags[] = {
|
|
|
|
{MO_GOT, "mips-got"},
|
|
|
|
{MO_GOT_CALL, "mips-got-call"},
|
|
|
|
{MO_GPREL, "mips-gprel"},
|
|
|
|
{MO_ABS_HI, "mips-abs-hi"},
|
|
|
|
{MO_ABS_LO, "mips-abs-lo"},
|
|
|
|
{MO_TLSGD, "mips-tlsgd"},
|
|
|
|
{MO_TLSLDM, "mips-tlsldm"},
|
|
|
|
{MO_DTPREL_HI, "mips-dtprel-hi"},
|
|
|
|
{MO_DTPREL_LO, "mips-dtprel-lo"},
|
|
|
|
{MO_GOTTPREL, "mips-gottprel"},
|
|
|
|
{MO_TPREL_HI, "mips-tprel-hi"},
|
|
|
|
{MO_TPREL_LO, "mips-tprel-lo"},
|
|
|
|
{MO_GPOFF_HI, "mips-gpoff-hi"},
|
|
|
|
{MO_GPOFF_LO, "mips-gpoff-lo"},
|
|
|
|
{MO_GOT_DISP, "mips-got-disp"},
|
|
|
|
{MO_GOT_PAGE, "mips-got-page"},
|
|
|
|
{MO_GOT_OFST, "mips-got-ofst"},
|
|
|
|
{MO_HIGHER, "mips-higher"},
|
|
|
|
{MO_HIGHEST, "mips-highest"},
|
|
|
|
{MO_GOT_HI16, "mips-got-hi16"},
|
|
|
|
{MO_GOT_LO16, "mips-got-lo16"},
|
|
|
|
{MO_CALL_HI16, "mips-call-hi16"},
|
|
|
|
{MO_CALL_LO16, "mips-call-lo16"}
|
|
|
|
};
|
|
|
|
return makeArrayRef(Flags);
|
|
|
|
}
|