2012-02-18 20:03:15 +08:00
|
|
|
//===-- XCoreInstrInfo.cpp - XCore Instruction Information ----------------===//
|
2008-11-07 18:59:00 +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
|
2008-11-07 18:59:00 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the XCore implementation of the TargetInstrInfo class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "XCoreInstrInfo.h"
|
|
|
|
#include "XCore.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "XCoreMachineFunctionInfo.h"
|
2010-04-05 13:48:36 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2014-01-06 22:20:37 +08:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2014-02-18 19:21:53 +08:00
|
|
|
#include "llvm/CodeGen/MachineMemOperand.h"
|
2014-01-06 22:20:37 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2008-11-07 18:59:00 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-12 04:10:48 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2011-08-25 02:08:43 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2008-11-07 18:59:00 +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
|
2011-06-29 04:07:07 +08:00
|
|
|
#include "XCoreGenInstrInfo.inc"
|
|
|
|
|
2008-11-07 18:59:00 +08:00
|
|
|
namespace llvm {
|
|
|
|
namespace XCore {
|
|
|
|
|
|
|
|
// XCore Condition Codes
|
|
|
|
enum CondCode {
|
|
|
|
COND_TRUE,
|
|
|
|
COND_FALSE,
|
|
|
|
COND_INVALID
|
|
|
|
};
|
|
|
|
}
|
2015-06-23 17:49:53 +08:00
|
|
|
}
|
2008-11-07 18:59:00 +08:00
|
|
|
|
2013-11-19 08:57:56 +08:00
|
|
|
// Pin the vtable to this file.
|
|
|
|
void XCoreInstrInfo::anchor() {}
|
|
|
|
|
2009-08-13 06:10:57 +08:00
|
|
|
XCoreInstrInfo::XCoreInstrInfo()
|
2011-07-02 01:57:27 +08:00
|
|
|
: XCoreGenInstrInfo(XCore::ADJCALLSTACKDOWN, XCore::ADJCALLSTACKUP),
|
2013-06-08 05:04:35 +08:00
|
|
|
RI() {
|
2008-11-07 18:59:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool isZeroImm(const MachineOperand &op) {
|
|
|
|
return op.isImm() && op.getImm() == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// isLoadFromStackSlot - If the specified machine instruction is a direct
|
|
|
|
/// load from a stack slot, return the virtual or physical register number of
|
|
|
|
/// the destination along with the FrameIndex of the loaded stack slot. If
|
|
|
|
/// not, return 0. This predicate must return 0 if the instruction has
|
|
|
|
/// any side effects other than loading from the stack slot.
|
2016-06-30 08:01:54 +08:00
|
|
|
unsigned XCoreInstrInfo::isLoadFromStackSlot(const MachineInstr &MI,
|
|
|
|
int &FrameIndex) const {
|
|
|
|
int Opcode = MI.getOpcode();
|
2018-07-31 03:41:25 +08:00
|
|
|
if (Opcode == XCore::LDWFI)
|
2008-11-07 18:59:00 +08:00
|
|
|
{
|
2016-06-30 08:01:54 +08:00
|
|
|
if ((MI.getOperand(1).isFI()) && // is a stack slot
|
|
|
|
(MI.getOperand(2).isImm()) && // the imm is zero
|
|
|
|
(isZeroImm(MI.getOperand(2)))) {
|
|
|
|
FrameIndex = MI.getOperand(1).getIndex();
|
|
|
|
return MI.getOperand(0).getReg();
|
2008-11-07 18:59:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2008-11-07 18:59:00 +08:00
|
|
|
/// isStoreToStackSlot - If the specified machine instruction is a direct
|
|
|
|
/// store to a stack slot, return the virtual or physical register number of
|
|
|
|
/// the source reg along with the FrameIndex of the loaded stack slot. If
|
|
|
|
/// not, return 0. This predicate must return 0 if the instruction has
|
|
|
|
/// any side effects other than storing to the stack slot.
|
2016-06-30 08:01:54 +08:00
|
|
|
unsigned XCoreInstrInfo::isStoreToStackSlot(const MachineInstr &MI,
|
|
|
|
int &FrameIndex) const {
|
|
|
|
int Opcode = MI.getOpcode();
|
2009-01-15 02:26:46 +08:00
|
|
|
if (Opcode == XCore::STWFI)
|
2008-11-07 18:59:00 +08:00
|
|
|
{
|
2016-06-30 08:01:54 +08:00
|
|
|
if ((MI.getOperand(1).isFI()) && // is a stack slot
|
|
|
|
(MI.getOperand(2).isImm()) && // the imm is zero
|
|
|
|
(isZeroImm(MI.getOperand(2)))) {
|
|
|
|
FrameIndex = MI.getOperand(1).getIndex();
|
|
|
|
return MI.getOperand(0).getReg();
|
2008-11-07 18:59:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Branch Analysis
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static inline bool IsBRU(unsigned BrOpc) {
|
|
|
|
return BrOpc == XCore::BRFU_u6
|
|
|
|
|| BrOpc == XCore::BRFU_lu6
|
|
|
|
|| BrOpc == XCore::BRBU_u6
|
|
|
|
|| BrOpc == XCore::BRBU_lu6;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IsBRT(unsigned BrOpc) {
|
|
|
|
return BrOpc == XCore::BRFT_ru6
|
|
|
|
|| BrOpc == XCore::BRFT_lru6
|
|
|
|
|| BrOpc == XCore::BRBT_ru6
|
|
|
|
|| BrOpc == XCore::BRBT_lru6;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IsBRF(unsigned BrOpc) {
|
|
|
|
return BrOpc == XCore::BRFF_ru6
|
|
|
|
|| BrOpc == XCore::BRFF_lru6
|
|
|
|
|| BrOpc == XCore::BRBF_ru6
|
|
|
|
|| BrOpc == XCore::BRBF_lru6;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IsCondBranch(unsigned BrOpc) {
|
|
|
|
return IsBRF(BrOpc) || IsBRT(BrOpc);
|
|
|
|
}
|
|
|
|
|
2010-02-23 21:25:07 +08:00
|
|
|
static inline bool IsBR_JT(unsigned BrOpc) {
|
|
|
|
return BrOpc == XCore::BR_JT
|
|
|
|
|| BrOpc == XCore::BR_JT32;
|
|
|
|
}
|
|
|
|
|
2018-07-31 03:41:25 +08:00
|
|
|
/// GetCondFromBranchOpc - Return the XCore CC that matches
|
2008-11-07 18:59:00 +08:00
|
|
|
/// the correspondent Branch instruction opcode.
|
2018-07-31 03:41:25 +08:00
|
|
|
static XCore::CondCode GetCondFromBranchOpc(unsigned BrOpc)
|
2008-11-07 18:59:00 +08:00
|
|
|
{
|
|
|
|
if (IsBRT(BrOpc)) {
|
|
|
|
return XCore::COND_TRUE;
|
|
|
|
} else if (IsBRF(BrOpc)) {
|
|
|
|
return XCore::COND_FALSE;
|
|
|
|
} else {
|
|
|
|
return XCore::COND_INVALID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// GetCondBranchFromCond - Return the Branch instruction
|
|
|
|
/// opcode that matches the cc.
|
2018-07-31 03:41:25 +08:00
|
|
|
static inline unsigned GetCondBranchFromCond(XCore::CondCode CC)
|
2008-11-07 18:59:00 +08:00
|
|
|
{
|
|
|
|
switch (CC) {
|
2009-07-15 00:55:14 +08:00
|
|
|
default: llvm_unreachable("Illegal condition code!");
|
2008-11-07 18:59:00 +08:00
|
|
|
case XCore::COND_TRUE : return XCore::BRFT_lru6;
|
|
|
|
case XCore::COND_FALSE : return XCore::BRFF_lru6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-31 03:41:25 +08:00
|
|
|
/// GetOppositeBranchCondition - Return the inverse of the specified
|
2008-11-07 18:59:00 +08:00
|
|
|
/// condition, e.g. turning COND_E to COND_NE.
|
|
|
|
static inline XCore::CondCode GetOppositeBranchCondition(XCore::CondCode CC)
|
|
|
|
{
|
|
|
|
switch (CC) {
|
2009-07-15 00:55:14 +08:00
|
|
|
default: llvm_unreachable("Illegal condition code!");
|
2008-11-07 18:59:00 +08:00
|
|
|
case XCore::COND_TRUE : return XCore::COND_FALSE;
|
|
|
|
case XCore::COND_FALSE : return XCore::COND_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-21 23:47:35 +08:00
|
|
|
/// analyzeBranch - Analyze the branching code at the end of MBB, returning
|
2008-11-07 18:59:00 +08:00
|
|
|
/// true if it cannot be understood (e.g. it's a switch dispatch or isn't
|
|
|
|
/// implemented for a target). Upon success, this returns false and returns
|
|
|
|
/// with the following information in various cases:
|
|
|
|
///
|
|
|
|
/// 1. If this block ends with no branches (it just falls through to its succ)
|
|
|
|
/// just return false, leaving TBB/FBB null.
|
|
|
|
/// 2. If this block ends with only an unconditional branch, it sets TBB to be
|
|
|
|
/// the destination block.
|
|
|
|
/// 3. If this block ends with an conditional branch and it falls through to
|
|
|
|
/// an successor block, it sets TBB to be the branch destination block and a
|
|
|
|
/// list of operands that evaluate the condition. These
|
|
|
|
/// operands can be passed to other TargetInstrInfo methods to create new
|
|
|
|
/// branches.
|
|
|
|
/// 4. If this block ends with an conditional branch and an unconditional
|
|
|
|
/// block, it returns the 'true' destination in TBB, the 'false' destination
|
|
|
|
/// in FBB, and a list of operands that evaluate the condition. These
|
|
|
|
/// operands can be passed to other TargetInstrInfo methods to create new
|
|
|
|
/// branches.
|
|
|
|
///
|
2016-09-15 04:43:16 +08:00
|
|
|
/// Note that removeBranch and insertBranch must be implemented to support
|
2008-11-07 18:59:00 +08:00
|
|
|
/// cases where this method returns success.
|
|
|
|
///
|
2016-07-15 22:41:04 +08:00
|
|
|
bool XCoreInstrInfo::analyzeBranch(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock *&TBB,
|
|
|
|
MachineBasicBlock *&FBB,
|
|
|
|
SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
bool AllowModify) const {
|
2008-11-07 18:59:00 +08:00
|
|
|
// If the block has no terminators, it just falls into the block after it.
|
2015-06-25 21:28:24 +08:00
|
|
|
MachineBasicBlock::iterator I = MBB.getLastNonDebugInstr();
|
|
|
|
if (I == MBB.end())
|
2010-04-02 09:38:09 +08:00
|
|
|
return false;
|
2015-06-25 21:28:24 +08:00
|
|
|
|
2016-02-23 10:46:52 +08:00
|
|
|
if (!isUnpredicatedTerminator(*I))
|
2008-11-07 18:59:00 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Get the last instruction in the block.
|
2016-07-28 02:14:38 +08:00
|
|
|
MachineInstr *LastInst = &*I;
|
|
|
|
|
2008-11-07 18:59:00 +08:00
|
|
|
// If there is only one terminator instruction, process it.
|
2016-02-23 10:46:52 +08:00
|
|
|
if (I == MBB.begin() || !isUnpredicatedTerminator(*--I)) {
|
2008-11-07 18:59:00 +08:00
|
|
|
if (IsBRU(LastInst->getOpcode())) {
|
|
|
|
TBB = LastInst->getOperand(0).getMBB();
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2008-11-07 18:59:00 +08:00
|
|
|
XCore::CondCode BranchCode = GetCondFromBranchOpc(LastInst->getOpcode());
|
|
|
|
if (BranchCode == XCore::COND_INVALID)
|
|
|
|
return true; // Can't handle indirect branch.
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2008-11-07 18:59:00 +08:00
|
|
|
// Conditional branch
|
|
|
|
// Block ends with fall-through condbranch.
|
|
|
|
|
|
|
|
TBB = LastInst->getOperand(1).getMBB();
|
|
|
|
Cond.push_back(MachineOperand::CreateImm(BranchCode));
|
|
|
|
Cond.push_back(LastInst->getOperand(0));
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2008-11-07 18:59:00 +08:00
|
|
|
// Get the instruction before it if it's a terminator.
|
2016-07-28 02:14:38 +08:00
|
|
|
MachineInstr *SecondLastInst = &*I;
|
2008-11-07 18:59:00 +08:00
|
|
|
|
|
|
|
// If there are three terminators, we don't know what sort of block this is.
|
2016-02-23 10:46:52 +08:00
|
|
|
if (SecondLastInst && I != MBB.begin() && isUnpredicatedTerminator(*--I))
|
2008-11-07 18:59:00 +08:00
|
|
|
return true;
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2008-11-07 18:59:00 +08:00
|
|
|
unsigned SecondLastOpc = SecondLastInst->getOpcode();
|
|
|
|
XCore::CondCode BranchCode = GetCondFromBranchOpc(SecondLastOpc);
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2008-11-07 18:59:00 +08:00
|
|
|
// If the block ends with conditional branch followed by unconditional,
|
|
|
|
// handle it.
|
|
|
|
if (BranchCode != XCore::COND_INVALID
|
|
|
|
&& IsBRU(LastInst->getOpcode())) {
|
|
|
|
|
|
|
|
TBB = SecondLastInst->getOperand(1).getMBB();
|
|
|
|
Cond.push_back(MachineOperand::CreateImm(BranchCode));
|
|
|
|
Cond.push_back(SecondLastInst->getOperand(0));
|
|
|
|
|
|
|
|
FBB = LastInst->getOperand(0).getMBB();
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2008-11-07 18:59:00 +08:00
|
|
|
// If the block ends with two unconditional branches, handle it. The second
|
|
|
|
// one is not executed, so remove it.
|
2018-07-31 03:41:25 +08:00
|
|
|
if (IsBRU(SecondLastInst->getOpcode()) &&
|
2008-11-07 18:59:00 +08:00
|
|
|
IsBRU(LastInst->getOpcode())) {
|
|
|
|
TBB = SecondLastInst->getOperand(0).getMBB();
|
|
|
|
I = LastInst;
|
2009-02-09 15:14:22 +08:00
|
|
|
if (AllowModify)
|
|
|
|
I->eraseFromParent();
|
2008-11-07 18:59:00 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-02-23 21:25:07 +08:00
|
|
|
// Likewise if it ends with a branch table followed by an unconditional branch.
|
|
|
|
if (IsBR_JT(SecondLastInst->getOpcode()) && IsBRU(LastInst->getOpcode())) {
|
|
|
|
I = LastInst;
|
|
|
|
if (AllowModify)
|
|
|
|
I->eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-11-07 18:59:00 +08:00
|
|
|
// Otherwise, can't handle this.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-15 01:24:15 +08:00
|
|
|
unsigned XCoreInstrInfo::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 {
|
2008-11-07 18:59:00 +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");
|
2008-11-07 18:59:00 +08:00
|
|
|
assert((Cond.size() == 2 || Cond.size() == 0) &&
|
|
|
|
"Unexpected number of components!");
|
2016-09-15 01:23:48 +08:00
|
|
|
assert(!BytesAdded && "code size not handled");
|
|
|
|
|
2014-04-25 13:30:21 +08:00
|
|
|
if (!FBB) { // One way branch.
|
2008-11-07 18:59:00 +08:00
|
|
|
if (Cond.empty()) {
|
|
|
|
// Unconditional branch
|
2010-06-18 06:43:56 +08:00
|
|
|
BuildMI(&MBB, DL, get(XCore::BRFU_lu6)).addMBB(TBB);
|
2008-11-07 18:59:00 +08:00
|
|
|
} else {
|
|
|
|
// Conditional branch.
|
|
|
|
unsigned Opc = GetCondBranchFromCond((XCore::CondCode)Cond[0].getImm());
|
2010-06-18 06:43:56 +08:00
|
|
|
BuildMI(&MBB, DL, get(Opc)).addReg(Cond[1].getReg())
|
2008-11-07 18:59:00 +08:00
|
|
|
.addMBB(TBB);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2008-11-07 18:59:00 +08:00
|
|
|
// Two-way Conditional branch.
|
|
|
|
assert(Cond.size() == 2 && "Unexpected number of components!");
|
|
|
|
unsigned Opc = GetCondBranchFromCond((XCore::CondCode)Cond[0].getImm());
|
2010-06-18 06:43:56 +08:00
|
|
|
BuildMI(&MBB, DL, get(Opc)).addReg(Cond[1].getReg())
|
2008-11-07 18:59:00 +08:00
|
|
|
.addMBB(TBB);
|
2010-06-18 06:43:56 +08:00
|
|
|
BuildMI(&MBB, DL, get(XCore::BRFU_lu6)).addMBB(FBB);
|
2008-11-07 18:59:00 +08:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned
|
2016-09-15 04:43:16 +08:00
|
|
|
XCoreInstrInfo::removeBranch(MachineBasicBlock &MBB, int *BytesRemoved) const {
|
2016-09-15 01:23:48 +08:00
|
|
|
assert(!BytesRemoved && "code size not handled");
|
|
|
|
|
2015-06-25 21:28:24 +08:00
|
|
|
MachineBasicBlock::iterator I = MBB.getLastNonDebugInstr();
|
|
|
|
if (I == MBB.end())
|
|
|
|
return 0;
|
|
|
|
|
2008-11-07 18:59:00 +08:00
|
|
|
if (!IsBRU(I->getOpcode()) && !IsCondBranch(I->getOpcode()))
|
|
|
|
return 0;
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2008-11-07 18:59:00 +08:00
|
|
|
// Remove the branch.
|
|
|
|
I->eraseFromParent();
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2008-11-07 18:59:00 +08:00
|
|
|
I = MBB.end();
|
|
|
|
|
|
|
|
if (I == MBB.begin()) return 1;
|
|
|
|
--I;
|
|
|
|
if (!IsCondBranch(I->getOpcode()))
|
|
|
|
return 1;
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2008-11-07 18:59:00 +08:00
|
|
|
// Remove the branch.
|
|
|
|
I->eraseFromParent();
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2010-07-11 15:56:13 +08:00
|
|
|
void XCoreInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
|
2016-06-12 23:39:02 +08:00
|
|
|
MachineBasicBlock::iterator I,
|
2019-11-11 16:24:21 +08:00
|
|
|
const DebugLoc &DL, MCRegister DestReg,
|
|
|
|
MCRegister SrcReg, bool KillSrc) const {
|
2010-07-11 15:56:13 +08:00
|
|
|
bool GRDest = XCore::GRRegsRegClass.contains(DestReg);
|
|
|
|
bool GRSrc = XCore::GRRegsRegClass.contains(SrcReg);
|
|
|
|
|
|
|
|
if (GRDest && GRSrc) {
|
|
|
|
BuildMI(MBB, I, DL, get(XCore::ADD_2rus), DestReg)
|
|
|
|
.addReg(SrcReg, getKillRegState(KillSrc))
|
|
|
|
.addImm(0);
|
|
|
|
return;
|
2008-11-07 18:59:00 +08:00
|
|
|
}
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2010-07-11 15:56:13 +08:00
|
|
|
if (GRDest && SrcReg == XCore::SP) {
|
|
|
|
BuildMI(MBB, I, DL, get(XCore::LDAWSP_ru6), DestReg).addImm(0);
|
|
|
|
return;
|
2008-11-07 18:59:00 +08:00
|
|
|
}
|
2010-07-11 15:56:13 +08:00
|
|
|
|
|
|
|
if (DestReg == XCore::SP && GRSrc) {
|
2009-02-12 08:02:55 +08:00
|
|
|
BuildMI(MBB, I, DL, get(XCore::SETSP_1r))
|
2010-07-11 15:56:13 +08:00
|
|
|
.addReg(SrcReg, getKillRegState(KillSrc));
|
|
|
|
return;
|
2008-11-07 18:59:00 +08:00
|
|
|
}
|
2010-07-11 15:56:13 +08:00
|
|
|
llvm_unreachable("Impossible reg-to-reg copy");
|
2008-11-07 18:59:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void XCoreInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
|
2009-02-12 08:02:55 +08:00
|
|
|
MachineBasicBlock::iterator I,
|
[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,
|
2009-02-12 08:02:55 +08:00
|
|
|
int FrameIndex,
|
2010-05-07 03:06:44 +08:00
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
const TargetRegisterInfo *TRI) const
|
2008-11-07 18:59:00 +08:00
|
|
|
{
|
2010-04-03 04:16:16 +08:00
|
|
|
DebugLoc DL;
|
2018-05-09 10:42:00 +08:00
|
|
|
if (I != MBB.end() && !I->isDebugInstr())
|
2014-07-04 14:38:22 +08:00
|
|
|
DL = I->getDebugLoc();
|
2014-02-18 19:21:53 +08:00
|
|
|
MachineFunction *MF = MBB.getParent();
|
2016-07-29 02:40:00 +08:00
|
|
|
const MachineFrameInfo &MFI = MF->getFrameInfo();
|
2015-08-12 07:09:45 +08:00
|
|
|
MachineMemOperand *MMO = MF->getMachineMemOperand(
|
|
|
|
MachinePointerInfo::getFixedStack(*MF, FrameIndex),
|
|
|
|
MachineMemOperand::MOStore, MFI.getObjectSize(FrameIndex),
|
[Alignment][NFC] Use Align version of getMachineMemOperand
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790
Reviewers: courbet
Subscribers: jyknight, sdardis, nemanjai, hiraditya, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, jfb, PkmX, jocewei, Jim, lenary, s.egerton, pzheng, sameer.abuasal, apazos, luismarques, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D77059
2020-03-30 22:45:57 +08:00
|
|
|
MFI.getObjectAlign(FrameIndex));
|
2009-02-12 08:02:55 +08:00
|
|
|
BuildMI(MBB, I, DL, get(XCore::STWFI))
|
2009-05-14 05:33:08 +08:00
|
|
|
.addReg(SrcReg, getKillRegState(isKill))
|
2009-02-12 08:02:55 +08:00
|
|
|
.addFrameIndex(FrameIndex)
|
2014-02-18 19:21:53 +08:00
|
|
|
.addImm(0)
|
|
|
|
.addMemOperand(MMO);
|
2008-11-07 18:59:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void XCoreInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
|
2009-02-12 08:02:55 +08:00
|
|
|
MachineBasicBlock::iterator I,
|
[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,
|
2010-05-07 03:06:44 +08:00
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
const TargetRegisterInfo *TRI) const
|
2008-11-07 18:59:00 +08:00
|
|
|
{
|
2010-04-03 04:16:16 +08:00
|
|
|
DebugLoc DL;
|
2018-05-09 10:42:00 +08:00
|
|
|
if (I != MBB.end() && !I->isDebugInstr())
|
2014-07-04 14:38:22 +08:00
|
|
|
DL = I->getDebugLoc();
|
2014-02-18 19:21:53 +08:00
|
|
|
MachineFunction *MF = MBB.getParent();
|
2016-07-29 02:40:00 +08:00
|
|
|
const MachineFrameInfo &MFI = MF->getFrameInfo();
|
2015-08-12 07:09:45 +08:00
|
|
|
MachineMemOperand *MMO = MF->getMachineMemOperand(
|
|
|
|
MachinePointerInfo::getFixedStack(*MF, FrameIndex),
|
|
|
|
MachineMemOperand::MOLoad, MFI.getObjectSize(FrameIndex),
|
[Alignment][NFC] Use Align version of getMachineMemOperand
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790
Reviewers: courbet
Subscribers: jyknight, sdardis, nemanjai, hiraditya, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, jfb, PkmX, jocewei, Jim, lenary, s.egerton, pzheng, sameer.abuasal, apazos, luismarques, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D77059
2020-03-30 22:45:57 +08:00
|
|
|
MFI.getObjectAlign(FrameIndex));
|
2009-02-12 08:02:55 +08:00
|
|
|
BuildMI(MBB, I, DL, get(XCore::LDWFI), DestReg)
|
|
|
|
.addFrameIndex(FrameIndex)
|
2014-02-18 19:21:53 +08:00
|
|
|
.addImm(0)
|
|
|
|
.addMemOperand(MMO);
|
2008-11-07 18:59:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool XCoreInstrInfo::
|
2016-09-15 04:43:16 +08:00
|
|
|
reverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
|
|
|
|
assert((Cond.size() == 2) &&
|
2008-11-07 18:59:00 +08:00
|
|
|
"Invalid XCore branch condition!");
|
|
|
|
Cond[0].setImm(GetOppositeBranchCondition((XCore::CondCode)Cond[0].getImm()));
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-06 22:20:37 +08:00
|
|
|
|
|
|
|
static inline bool isImmU6(unsigned val) {
|
|
|
|
return val < (1 << 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool isImmU16(unsigned val) {
|
|
|
|
return val < (1 << 16);
|
|
|
|
}
|
|
|
|
|
2014-04-14 20:30:35 +08:00
|
|
|
static bool isImmMskBitp(unsigned val) {
|
|
|
|
if (!isMask_32(val)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int N = Log2_32(val) + 1;
|
|
|
|
return (N >= 1 && N <= 8) || N == 16 || N == 24 || N == 32;
|
|
|
|
}
|
|
|
|
|
2014-01-06 22:20:37 +08:00
|
|
|
MachineBasicBlock::iterator XCoreInstrInfo::loadImmediate(
|
|
|
|
MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned Reg, uint64_t Value) const {
|
|
|
|
DebugLoc dl;
|
2018-05-09 10:42:00 +08:00
|
|
|
if (MI != MBB.end() && !MI->isDebugInstr())
|
2014-07-04 14:38:22 +08:00
|
|
|
dl = MI->getDebugLoc();
|
2014-04-14 20:30:35 +08:00
|
|
|
if (isImmMskBitp(Value)) {
|
2014-01-06 22:20:37 +08:00
|
|
|
int N = Log2_32(Value) + 1;
|
2014-11-01 07:19:46 +08:00
|
|
|
return BuildMI(MBB, MI, dl, get(XCore::MKMSK_rus), Reg)
|
|
|
|
.addImm(N)
|
|
|
|
.getInstr();
|
2014-01-06 22:20:37 +08:00
|
|
|
}
|
|
|
|
if (isImmU16(Value)) {
|
|
|
|
int Opcode = isImmU6(Value) ? XCore::LDC_ru6 : XCore::LDC_lru6;
|
2014-11-01 07:19:46 +08:00
|
|
|
return BuildMI(MBB, MI, dl, get(Opcode), Reg).addImm(Value).getInstr();
|
2014-01-06 22:20:37 +08:00
|
|
|
}
|
|
|
|
MachineConstantPool *ConstantPool = MBB.getParent()->getConstantPool();
|
|
|
|
const Constant *C = ConstantInt::get(
|
2017-12-16 06:22:58 +08:00
|
|
|
Type::getInt32Ty(MBB.getParent()->getFunction().getContext()), Value);
|
2020-05-13 00:43:24 +08:00
|
|
|
unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align(4));
|
2014-01-06 22:20:37 +08:00
|
|
|
return BuildMI(MBB, MI, dl, get(XCore::LDWCP_lru6), Reg)
|
2014-11-01 07:19:46 +08:00
|
|
|
.addConstantPoolIndex(Idx)
|
|
|
|
.getInstr();
|
2014-01-06 22:20:37 +08:00
|
|
|
}
|