2014-05-24 20:50:23 +08:00
|
|
|
//===- AArch64InstrInfo.h - AArch64 Instruction Information -----*- C++ -*-===//
|
2014-03-29 18:18:08 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2014-05-24 20:50:23 +08:00
|
|
|
// This file contains the AArch64 implementation of the TargetInstrInfo class.
|
2014-03-29 18:18:08 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_TARGET_AARCH64_AARCH64INSTRINFO_H
|
|
|
|
#define LLVM_LIB_TARGET_AARCH64_AARCH64INSTRINFO_H
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
#include "AArch64.h"
|
|
|
|
#include "AArch64RegisterInfo.h"
|
2014-08-08 05:40:58 +08:00
|
|
|
#include "llvm/CodeGen/MachineCombinerPattern.h"
|
2017-11-08 09:01:31 +08:00
|
|
|
#include "llvm/CodeGen/TargetInstrInfo.h"
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
#define GET_INSTRINFO_HEADER
|
2014-05-24 20:50:23 +08:00
|
|
|
#include "AArch64GenInstrInfo.inc"
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
class AArch64Subtarget;
|
|
|
|
class AArch64TargetMachine;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2017-07-15 05:44:12 +08:00
|
|
|
static const MachineMemOperand::Flags MOSuppressPair =
|
|
|
|
MachineMemOperand::MOTargetFlag1;
|
|
|
|
static const MachineMemOperand::Flags MOStridedAccess =
|
|
|
|
MachineMemOperand::MOTargetFlag2;
|
|
|
|
|
|
|
|
#define FALKOR_STRIDED_ACCESS_MD "falkor.strided.access"
|
|
|
|
|
2016-07-27 22:31:46 +08:00
|
|
|
class AArch64InstrInfo final : public AArch64GenInstrInfo {
|
2015-03-19 04:37:30 +08:00
|
|
|
const AArch64RegisterInfo RI;
|
2014-05-24 20:50:23 +08:00
|
|
|
const AArch64Subtarget &Subtarget;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
public:
|
2014-05-24 20:50:23 +08:00
|
|
|
explicit AArch64InstrInfo(const AArch64Subtarget &STI);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2015-03-19 04:37:30 +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).
|
|
|
|
const AArch64RegisterInfo &getRegisterInfo() const { return RI; }
|
|
|
|
|
2016-07-29 16:16:16 +08:00
|
|
|
unsigned getInstSizeInBytes(const MachineInstr &MI) const override;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2016-06-30 08:01:54 +08:00
|
|
|
bool isAsCheapAsAMove(const MachineInstr &MI) const override;
|
2014-07-29 10:09:26 +08:00
|
|
|
|
2014-03-30 15:25:18 +08:00
|
|
|
bool isCoalescableExtInstr(const MachineInstr &MI, unsigned &SrcReg,
|
|
|
|
unsigned &DstReg, unsigned &SubIdx) const override;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-09-08 22:43:48 +08:00
|
|
|
bool
|
2016-06-30 08:01:54 +08:00
|
|
|
areMemAccessesTriviallyDisjoint(MachineInstr &MIa, MachineInstr &MIb,
|
2014-09-08 22:43:48 +08:00
|
|
|
AliasAnalysis *AA = nullptr) const override;
|
|
|
|
|
2016-06-30 08:01:54 +08:00
|
|
|
unsigned isLoadFromStackSlot(const MachineInstr &MI,
|
2014-03-30 15:25:18 +08:00
|
|
|
int &FrameIndex) const override;
|
2016-06-30 08:01:54 +08:00
|
|
|
unsigned isStoreToStackSlot(const MachineInstr &MI,
|
2014-03-30 15:25:18 +08:00
|
|
|
int &FrameIndex) const override;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-05-20 06:59:51 +08:00
|
|
|
/// Returns true if there is a shiftable register and that the shift value
|
|
|
|
/// is non-zero.
|
2016-06-30 08:01:54 +08:00
|
|
|
bool hasShiftedReg(const MachineInstr &MI) const;
|
2014-05-20 06:59:51 +08:00
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
/// Returns true if there is an extendable register and that the extending
|
|
|
|
/// value is non-zero.
|
2016-06-30 08:01:54 +08:00
|
|
|
bool hasExtendedReg(const MachineInstr &MI) const;
|
2014-05-17 01:15:33 +08:00
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
/// \brief Does this instruction set its full destination register to zero?
|
2016-06-30 08:01:54 +08:00
|
|
|
bool isGPRZero(const MachineInstr &MI) const;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
/// \brief Does this instruction rename a GPR without modifying bits?
|
2016-06-30 08:01:54 +08:00
|
|
|
bool isGPRCopy(const MachineInstr &MI) const;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
/// \brief Does this instruction rename an FPR without modifying bits?
|
2016-06-30 08:01:54 +08:00
|
|
|
bool isFPRCopy(const MachineInstr &MI) const;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
/// Return true if this is load/store scales or extends its register offset.
|
|
|
|
/// This refers to scaling a dynamic index as opposed to scaled immediates.
|
|
|
|
/// MI should be a memory op that allows scaled addressing.
|
2016-06-30 08:01:54 +08:00
|
|
|
bool isScaledAddr(const MachineInstr &MI) const;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
/// Return true if pairing the given load or store is hinted to be
|
|
|
|
/// unprofitable.
|
2016-06-30 08:01:54 +08:00
|
|
|
bool isLdStPairSuppressed(const MachineInstr &MI) const;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2017-07-15 05:44:12 +08:00
|
|
|
/// Return true if the given load or store is a strided memory access.
|
|
|
|
bool isStridedAccess(const MachineInstr &MI) const;
|
|
|
|
|
2016-03-10 01:29:48 +08:00
|
|
|
/// Return true if this is an unscaled load/store.
|
|
|
|
bool isUnscaledLdSt(unsigned Opc) const;
|
|
|
|
|
|
|
|
/// Return true if this is an unscaled load/store.
|
2016-06-30 08:01:54 +08:00
|
|
|
bool isUnscaledLdSt(MachineInstr &MI) const;
|
2016-03-10 01:29:48 +08:00
|
|
|
|
2016-08-12 23:26:00 +08:00
|
|
|
static bool isPairableLdStInst(const MachineInstr &MI) {
|
|
|
|
switch (MI.getOpcode()) {
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
// Scaled instructions.
|
|
|
|
case AArch64::STRSui:
|
|
|
|
case AArch64::STRDui:
|
|
|
|
case AArch64::STRQui:
|
|
|
|
case AArch64::STRXui:
|
|
|
|
case AArch64::STRWui:
|
|
|
|
case AArch64::LDRSui:
|
|
|
|
case AArch64::LDRDui:
|
|
|
|
case AArch64::LDRQui:
|
|
|
|
case AArch64::LDRXui:
|
|
|
|
case AArch64::LDRWui:
|
|
|
|
case AArch64::LDRSWui:
|
|
|
|
// Unscaled instructions.
|
|
|
|
case AArch64::STURSi:
|
|
|
|
case AArch64::STURDi:
|
|
|
|
case AArch64::STURQi:
|
|
|
|
case AArch64::STURWi:
|
|
|
|
case AArch64::STURXi:
|
|
|
|
case AArch64::LDURSi:
|
|
|
|
case AArch64::LDURDi:
|
|
|
|
case AArch64::LDURQi:
|
|
|
|
case AArch64::LDURWi:
|
|
|
|
case AArch64::LDURXi:
|
|
|
|
case AArch64::LDURSWi:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[AArch64] Prefer Bcc to CBZ/CBNZ/TBZ/TBNZ when NZCV flags can be set for "free".
This patch contains a pass that transforms CBZ/CBNZ/TBZ/TBNZ instructions into a
conditional branch (Bcc), when the NZCV flags can be set for "free". This is
preferred on targets that have more flexibility when scheduling Bcc
instructions as compared to CBZ/CBNZ/TBZ/TBNZ (assuming all other variables are
equal). This can reduce register pressure and is also the default behavior for
GCC.
A few examples:
add w8, w0, w1 -> cmn w0, w1 ; CMN is an alias of ADDS.
cbz w8, .LBB_2 -> b.eq .LBB0_2 ; single def/use of w8 removed.
add w8, w0, w1 -> adds w8, w0, w1 ; w8 has multiple uses.
cbz w8, .LBB1_2 -> b.eq .LBB1_2
sub w8, w0, w1 -> subs w8, w0, w1 ; w8 has multiple uses.
tbz w8, #31, .LBB6_2 -> b.ge .LBB6_2
In looking at all current sub-target machine descriptions, this transformation
appears to be either positive or neutral.
Differential Revision: https://reviews.llvm.org/D34220.
llvm-svn: 306144
2017-06-24 03:20:12 +08:00
|
|
|
/// \brief Return the opcode that set flags when possible. The caller is
|
|
|
|
/// responsible for ensuring the opc has a flag setting equivalent.
|
|
|
|
static unsigned convertToFlagSettingOpc(unsigned Opc, bool &Is64Bit) {
|
|
|
|
switch (Opc) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Opcode has no flag setting equivalent!");
|
|
|
|
// 32-bit cases:
|
2017-07-29 10:55:46 +08:00
|
|
|
case AArch64::ADDWri:
|
|
|
|
Is64Bit = false;
|
|
|
|
return AArch64::ADDSWri;
|
|
|
|
case AArch64::ADDWrr:
|
|
|
|
Is64Bit = false;
|
|
|
|
return AArch64::ADDSWrr;
|
|
|
|
case AArch64::ADDWrs:
|
|
|
|
Is64Bit = false;
|
|
|
|
return AArch64::ADDSWrs;
|
|
|
|
case AArch64::ADDWrx:
|
|
|
|
Is64Bit = false;
|
|
|
|
return AArch64::ADDSWrx;
|
|
|
|
case AArch64::ANDWri:
|
|
|
|
Is64Bit = false;
|
|
|
|
return AArch64::ANDSWri;
|
|
|
|
case AArch64::ANDWrr:
|
|
|
|
Is64Bit = false;
|
|
|
|
return AArch64::ANDSWrr;
|
|
|
|
case AArch64::ANDWrs:
|
|
|
|
Is64Bit = false;
|
|
|
|
return AArch64::ANDSWrs;
|
|
|
|
case AArch64::BICWrr:
|
|
|
|
Is64Bit = false;
|
|
|
|
return AArch64::BICSWrr;
|
|
|
|
case AArch64::BICWrs:
|
|
|
|
Is64Bit = false;
|
|
|
|
return AArch64::BICSWrs;
|
|
|
|
case AArch64::SUBWri:
|
|
|
|
Is64Bit = false;
|
|
|
|
return AArch64::SUBSWri;
|
|
|
|
case AArch64::SUBWrr:
|
|
|
|
Is64Bit = false;
|
|
|
|
return AArch64::SUBSWrr;
|
|
|
|
case AArch64::SUBWrs:
|
|
|
|
Is64Bit = false;
|
|
|
|
return AArch64::SUBSWrs;
|
|
|
|
case AArch64::SUBWrx:
|
|
|
|
Is64Bit = false;
|
|
|
|
return AArch64::SUBSWrx;
|
[AArch64] Prefer Bcc to CBZ/CBNZ/TBZ/TBNZ when NZCV flags can be set for "free".
This patch contains a pass that transforms CBZ/CBNZ/TBZ/TBNZ instructions into a
conditional branch (Bcc), when the NZCV flags can be set for "free". This is
preferred on targets that have more flexibility when scheduling Bcc
instructions as compared to CBZ/CBNZ/TBZ/TBNZ (assuming all other variables are
equal). This can reduce register pressure and is also the default behavior for
GCC.
A few examples:
add w8, w0, w1 -> cmn w0, w1 ; CMN is an alias of ADDS.
cbz w8, .LBB_2 -> b.eq .LBB0_2 ; single def/use of w8 removed.
add w8, w0, w1 -> adds w8, w0, w1 ; w8 has multiple uses.
cbz w8, .LBB1_2 -> b.eq .LBB1_2
sub w8, w0, w1 -> subs w8, w0, w1 ; w8 has multiple uses.
tbz w8, #31, .LBB6_2 -> b.ge .LBB6_2
In looking at all current sub-target machine descriptions, this transformation
appears to be either positive or neutral.
Differential Revision: https://reviews.llvm.org/D34220.
llvm-svn: 306144
2017-06-24 03:20:12 +08:00
|
|
|
// 64-bit cases:
|
2017-07-29 10:55:46 +08:00
|
|
|
case AArch64::ADDXri:
|
|
|
|
Is64Bit = true;
|
|
|
|
return AArch64::ADDSXri;
|
|
|
|
case AArch64::ADDXrr:
|
|
|
|
Is64Bit = true;
|
|
|
|
return AArch64::ADDSXrr;
|
|
|
|
case AArch64::ADDXrs:
|
|
|
|
Is64Bit = true;
|
|
|
|
return AArch64::ADDSXrs;
|
|
|
|
case AArch64::ADDXrx:
|
|
|
|
Is64Bit = true;
|
|
|
|
return AArch64::ADDSXrx;
|
|
|
|
case AArch64::ANDXri:
|
|
|
|
Is64Bit = true;
|
|
|
|
return AArch64::ANDSXri;
|
|
|
|
case AArch64::ANDXrr:
|
|
|
|
Is64Bit = true;
|
|
|
|
return AArch64::ANDSXrr;
|
|
|
|
case AArch64::ANDXrs:
|
|
|
|
Is64Bit = true;
|
|
|
|
return AArch64::ANDSXrs;
|
|
|
|
case AArch64::BICXrr:
|
|
|
|
Is64Bit = true;
|
|
|
|
return AArch64::BICSXrr;
|
|
|
|
case AArch64::BICXrs:
|
|
|
|
Is64Bit = true;
|
|
|
|
return AArch64::BICSXrs;
|
|
|
|
case AArch64::SUBXri:
|
|
|
|
Is64Bit = true;
|
|
|
|
return AArch64::SUBSXri;
|
|
|
|
case AArch64::SUBXrr:
|
|
|
|
Is64Bit = true;
|
|
|
|
return AArch64::SUBSXrr;
|
|
|
|
case AArch64::SUBXrs:
|
|
|
|
Is64Bit = true;
|
|
|
|
return AArch64::SUBSXrs;
|
|
|
|
case AArch64::SUBXrx:
|
|
|
|
Is64Bit = true;
|
|
|
|
return AArch64::SUBSXrx;
|
[AArch64] Prefer Bcc to CBZ/CBNZ/TBZ/TBNZ when NZCV flags can be set for "free".
This patch contains a pass that transforms CBZ/CBNZ/TBZ/TBNZ instructions into a
conditional branch (Bcc), when the NZCV flags can be set for "free". This is
preferred on targets that have more flexibility when scheduling Bcc
instructions as compared to CBZ/CBNZ/TBZ/TBNZ (assuming all other variables are
equal). This can reduce register pressure and is also the default behavior for
GCC.
A few examples:
add w8, w0, w1 -> cmn w0, w1 ; CMN is an alias of ADDS.
cbz w8, .LBB_2 -> b.eq .LBB0_2 ; single def/use of w8 removed.
add w8, w0, w1 -> adds w8, w0, w1 ; w8 has multiple uses.
cbz w8, .LBB1_2 -> b.eq .LBB1_2
sub w8, w0, w1 -> subs w8, w0, w1 ; w8 has multiple uses.
tbz w8, #31, .LBB6_2 -> b.ge .LBB6_2
In looking at all current sub-target machine descriptions, this transformation
appears to be either positive or neutral.
Differential Revision: https://reviews.llvm.org/D34220.
llvm-svn: 306144
2017-06-24 03:20:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-19 03:21:02 +08:00
|
|
|
/// Return true if this is a load/store that can be potentially paired/merged.
|
2016-06-30 08:01:54 +08:00
|
|
|
bool isCandidateToMergeOrPair(MachineInstr &MI) const;
|
2016-03-19 03:21:02 +08:00
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
/// Hint that pairing the given load or store is unprofitable.
|
2016-06-30 08:01:54 +08:00
|
|
|
void suppressLdStPair(MachineInstr &MI) const;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2016-06-30 08:01:54 +08:00
|
|
|
bool getMemOpBaseRegImmOfs(MachineInstr &LdSt, unsigned &BaseReg,
|
2016-03-10 00:00:35 +08:00
|
|
|
int64_t &Offset,
|
2015-06-16 02:44:14 +08:00
|
|
|
const TargetRegisterInfo *TRI) const override;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2016-06-30 08:01:54 +08:00
|
|
|
bool getMemOpBaseRegImmOfsWidth(MachineInstr &LdSt, unsigned &BaseReg,
|
2016-03-10 00:46:48 +08:00
|
|
|
int64_t &Offset, unsigned &Width,
|
2015-06-16 02:44:14 +08:00
|
|
|
const TargetRegisterInfo *TRI) const;
|
2014-09-08 22:43:48 +08:00
|
|
|
|
2017-03-18 06:26:55 +08:00
|
|
|
/// Return the immediate offset of the base register in a load/store \p LdSt.
|
|
|
|
MachineOperand &getMemOpBaseRegImmOfsOffsetOperand(MachineInstr &LdSt) const;
|
|
|
|
|
|
|
|
/// \brief Returns true if opcode \p Opc is a memory operation. If it is, set
|
|
|
|
/// \p Scale, \p Width, \p MinOffset, and \p MaxOffset accordingly.
|
|
|
|
///
|
|
|
|
/// For unscaled instructions, \p Scale is set to 1.
|
|
|
|
bool getMemOpInfo(unsigned Opcode, unsigned &Scale, unsigned &Width,
|
|
|
|
int64_t &MinOffset, int64_t &MaxOffset) const;
|
|
|
|
|
2017-09-14 06:20:47 +08:00
|
|
|
bool shouldClusterMemOps(MachineInstr &FirstLdSt, unsigned BaseReg1,
|
|
|
|
MachineInstr &SecondLdSt, unsigned BaseReg2,
|
2016-06-30 08:01:54 +08:00
|
|
|
unsigned NumLoads) const override;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
void copyPhysRegTuple(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
|
2016-06-12 23:39:02 +08:00
|
|
|
const DebugLoc &DL, unsigned DestReg, unsigned SrcReg,
|
2014-03-29 18:18:08 +08:00
|
|
|
bool KillSrc, unsigned Opcode,
|
|
|
|
llvm::ArrayRef<unsigned> Indices) const;
|
2014-03-30 15:25:18 +08:00
|
|
|
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
|
2016-06-12 23:39:02 +08:00
|
|
|
const DebugLoc &DL, unsigned DestReg, unsigned SrcReg,
|
2014-03-30 15:25:18 +08:00
|
|
|
bool KillSrc) const override;
|
|
|
|
|
|
|
|
void storeRegToStackSlot(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MBBI, unsigned SrcReg,
|
|
|
|
bool isKill, int FrameIndex,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
const TargetRegisterInfo *TRI) const override;
|
|
|
|
|
|
|
|
void loadRegFromStackSlot(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MBBI, unsigned DestReg,
|
|
|
|
int FrameIndex, const TargetRegisterClass *RC,
|
|
|
|
const TargetRegisterInfo *TRI) const override;
|
|
|
|
|
2017-01-06 05:51:42 +08:00
|
|
|
// This tells target independent code that it is okay to pass instructions
|
|
|
|
// with subreg operands to foldMemoryOperandImpl.
|
|
|
|
bool isSubregFoldable() const override { return true; }
|
|
|
|
|
2014-07-31 20:58:50 +08:00
|
|
|
using TargetInstrInfo::foldMemoryOperandImpl;
|
2016-06-30 08:01:54 +08:00
|
|
|
MachineInstr *
|
|
|
|
foldMemoryOperandImpl(MachineFunction &MF, MachineInstr &MI,
|
|
|
|
ArrayRef<unsigned> Ops,
|
|
|
|
MachineBasicBlock::iterator InsertPt, int FrameIndex,
|
|
|
|
LiveIntervals *LIS = nullptr) const override;
|
2014-03-30 15:25:18 +08:00
|
|
|
|
2016-08-02 16:06:17 +08:00
|
|
|
/// \returns true if a branch from an instruction with opcode \p BranchOpc
|
2016-10-06 23:38:09 +08:00
|
|
|
/// bytes is capable of jumping to a position \p BrOffset bytes away.
|
|
|
|
bool isBranchOffsetInRange(unsigned BranchOpc,
|
|
|
|
int64_t BrOffset) const override;
|
|
|
|
|
|
|
|
MachineBasicBlock *getBranchDestBlock(const MachineInstr &MI) const override;
|
2016-08-02 16:06:17 +08:00
|
|
|
|
2016-07-15 22:41:04 +08:00
|
|
|
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
|
2014-03-30 15:25:18 +08:00
|
|
|
MachineBasicBlock *&FBB,
|
|
|
|
SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
bool AllowModify = false) const override;
|
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;
|
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;
|
2014-03-30 15:25:18 +08:00
|
|
|
bool
|
2016-09-15 04:43:16 +08:00
|
|
|
reverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
|
2015-06-12 03:30:37 +08:00
|
|
|
bool canInsertSelect(const MachineBasicBlock &, ArrayRef<MachineOperand> Cond,
|
|
|
|
unsigned, unsigned, int &, int &, int &) const override;
|
2014-03-30 15:25:18 +08:00
|
|
|
void insertSelect(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
|
2016-06-12 23:39:02 +08:00
|
|
|
const DebugLoc &DL, unsigned DstReg,
|
|
|
|
ArrayRef<MachineOperand> Cond, unsigned TrueReg,
|
|
|
|
unsigned FalseReg) const override;
|
2017-04-22 05:48:41 +08:00
|
|
|
void getNoop(MCInst &NopInst) const override;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
/// analyzeCompare - For a comparison instruction, return the source registers
|
|
|
|
/// in SrcReg and SrcReg2, and the value it compares against in CmpValue.
|
|
|
|
/// Return true if the comparison instruction can be analyzed.
|
2016-06-30 08:01:54 +08:00
|
|
|
bool analyzeCompare(const MachineInstr &MI, unsigned &SrcReg,
|
2014-03-30 15:25:18 +08:00
|
|
|
unsigned &SrcReg2, int &CmpMask,
|
|
|
|
int &CmpValue) const override;
|
2014-03-29 18:18:08 +08:00
|
|
|
/// optimizeCompareInstr - Convert the instruction supplying the argument to
|
|
|
|
/// the comparison into one that sets the zero bit in the flags register.
|
2016-06-30 08:01:54 +08:00
|
|
|
bool optimizeCompareInstr(MachineInstr &CmpInstr, unsigned SrcReg,
|
2014-03-30 15:25:18 +08:00
|
|
|
unsigned SrcReg2, int CmpMask, int CmpValue,
|
|
|
|
const MachineRegisterInfo *MRI) const override;
|
2016-06-30 08:01:54 +08:00
|
|
|
bool optimizeCondBranch(MachineInstr &MI) const override;
|
2016-04-24 13:14:01 +08:00
|
|
|
|
|
|
|
/// Return true when a code sequence can improve throughput. It
|
|
|
|
/// should be called only for instructions in loops.
|
|
|
|
/// \param Pattern - combiner pattern
|
|
|
|
bool isThroughputPattern(MachineCombinerPattern Pattern) const override;
|
2015-06-20 07:21:42 +08:00
|
|
|
/// Return true when there is potentially a faster code sequence
|
2017-07-11 06:11:50 +08:00
|
|
|
/// for an instruction chain ending in ``Root``. All potential patterns are
|
|
|
|
/// listed in the ``Patterns`` array.
|
2017-07-29 10:55:46 +08:00
|
|
|
bool getMachineCombinerPatterns(
|
|
|
|
MachineInstr &Root,
|
|
|
|
SmallVectorImpl<MachineCombinerPattern> &Patterns) const override;
|
2016-01-07 12:01:02 +08:00
|
|
|
/// Return true when Inst is associative and commutative so that it can be
|
|
|
|
/// reassociated.
|
|
|
|
bool isAssociativeAndCommutative(const MachineInstr &Inst) const override;
|
2015-06-20 07:21:42 +08:00
|
|
|
/// When getMachineCombinerPatterns() finds patterns, this function generates
|
|
|
|
/// the instructions that could replace the original code sequence
|
2014-09-03 19:41:21 +08:00
|
|
|
void genAlternativeCodeSequence(
|
2015-11-06 03:34:57 +08:00
|
|
|
MachineInstr &Root, MachineCombinerPattern Pattern,
|
2014-08-08 05:40:58 +08:00
|
|
|
SmallVectorImpl<MachineInstr *> &InsInstrs,
|
|
|
|
SmallVectorImpl<MachineInstr *> &DelInstrs,
|
2014-09-03 19:41:21 +08:00
|
|
|
DenseMap<unsigned, unsigned> &InstrIdxForVirtReg) const override;
|
2016-05-02 22:56:21 +08:00
|
|
|
/// AArch64 supports MachineCombiner.
|
2014-09-03 19:41:21 +08:00
|
|
|
bool useMachineCombiner() const override;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2016-06-30 08:01:54 +08:00
|
|
|
bool expandPostRAPseudo(MachineInstr &MI) const override;
|
2015-08-19 06:52:15 +08:00
|
|
|
|
|
|
|
std::pair<unsigned, unsigned>
|
|
|
|
decomposeMachineOperandsTargetFlags(unsigned TF) const override;
|
|
|
|
ArrayRef<std::pair<unsigned, const char *>>
|
|
|
|
getSerializableDirectMachineOperandTargetFlags() const override;
|
|
|
|
ArrayRef<std::pair<unsigned, const char *>>
|
|
|
|
getSerializableBitmaskMachineOperandTargetFlags() const override;
|
2017-07-13 10:28:54 +08:00
|
|
|
ArrayRef<std::pair<MachineMemOperand::Flags, const char *>>
|
|
|
|
getSerializableMachineMemOperandTargetFlags() const override;
|
2015-08-19 06:52:15 +08:00
|
|
|
|
2017-09-28 04:47:39 +08:00
|
|
|
bool
|
|
|
|
canOutlineWithoutLRSave(MachineBasicBlock::iterator &CallInsertionPt) const;
|
[MachineOutliner] Disable outlining from LinkOnceODRs by default
Say you have two identical linkonceodr functions, one in M1 and one in M2.
Say that the outliner outlines A,B,C from one function, and D,E,F from another
function (where letters are instructions). Now those functions are not
identical, and cannot be deduped. Locally to M1 and M2, these outlining
choices would be good-- to the whole program, however, this might not be true!
To mitigate this, this commit makes it so that the outliner sees linkonceodr
functions as unsafe to outline from. It also adds a flag,
-enable-linkonceodr-outlining, which allows the user to specify that they
want to outline from such functions when they know what they're doing.
Changing this handles most code size regressions in the test suite caused by
competing with linker dedupe. It also doesn't have a huge impact on the code
size improvements from the outliner. There are 6 tests that regress > 5% from
outlining WITH linkonceodrs to outlining WITHOUT linkonceodrs. Overall, most
tests either improve or are not impacted.
Not outlined vs outlined without linkonceodrs:
https://hastebin.com/raw/qeguxavuda
Not outlined vs outlined with linkonceodrs:
https://hastebin.com/raw/edepoqoqic
Outlined with linkonceodrs vs outlined without linkonceodrs:
https://hastebin.com/raw/awiqifiheb
Numbers generated using compare.py with -m size.__text. Tests run for AArch64
with -Oz -mllvm -enable-machine-outliner -mno-red-zone.
llvm-svn: 315136
2017-10-07 08:16:34 +08:00
|
|
|
bool isFunctionSafeToOutlineFrom(MachineFunction &MF,
|
|
|
|
bool OutlineFromLinkOnceODRs) const override;
|
2017-09-28 04:47:39 +08:00
|
|
|
MachineOutlinerInfo getOutlininingCandidateInfo(
|
2017-07-29 10:55:46 +08:00
|
|
|
std::vector<
|
|
|
|
std::pair<MachineBasicBlock::iterator, MachineBasicBlock::iterator>>
|
2017-09-28 04:47:39 +08:00
|
|
|
&RepeatedSequenceLocs) const override;
|
2017-03-18 06:26:55 +08:00
|
|
|
AArch64GenInstrInfo::MachineOutlinerInstrType
|
[MachineOutliner] AArch64: Handle instrs that use SP and will never need fixups
This commit does two things. Firstly, it adds a collection of flags which can
be passed along to the target to encode information about the MBB that an
instruction lives in to the outliner.
Second, it adds some of those flags to the AArch64 outliner in order to add
more stack instructions to the list of legal instructions that are handled
by the outliner. The two flags added check if
- There are calls in the MachineBasicBlock containing the instruction
- The link register is available in the entire block
If the link register is available and there are no calls, then a stack
instruction can always be outlined without fixups, regardless of what it is,
since in this case, the outliner will never modify the stack to create a
call or outlined frame.
The motivation for doing this was checking which instructions are most often
missed by the outliner. Instructions like, say
%sp<def> = ADDXri %sp, 32, 0; flags: FrameDestroy
are very common, but cannot be outlined in the case that the outliner might
modify the stack. This commit allows us to outline instructions like this.
llvm-svn: 322048
2018-01-09 08:26:18 +08:00
|
|
|
getOutliningType(MachineBasicBlock::iterator &MIT, unsigned Flags) const override;
|
|
|
|
unsigned getMachineOutlinerMBBFlags(MachineBasicBlock &MBB) const override;
|
2017-07-29 10:55:46 +08:00
|
|
|
void insertOutlinerEpilogue(MachineBasicBlock &MBB, MachineFunction &MF,
|
2017-09-28 04:47:39 +08:00
|
|
|
const MachineOutlinerInfo &MInfo) const override;
|
2017-07-29 10:55:46 +08:00
|
|
|
void insertOutlinerPrologue(MachineBasicBlock &MBB, MachineFunction &MF,
|
2017-09-28 04:47:39 +08:00
|
|
|
const MachineOutlinerInfo &MInfo) const override;
|
2017-03-18 06:26:55 +08:00
|
|
|
MachineBasicBlock::iterator
|
|
|
|
insertOutlinedCall(Module &M, MachineBasicBlock &MBB,
|
2017-07-29 10:55:46 +08:00
|
|
|
MachineBasicBlock::iterator &It, MachineFunction &MF,
|
2017-09-28 04:47:39 +08:00
|
|
|
const MachineOutlinerInfo &MInfo) const override;
|
2017-08-29 06:51:32 +08:00
|
|
|
/// Returns true if the instruction has a shift left that can be executed
|
|
|
|
/// more efficiently.
|
|
|
|
bool isExynosShiftLeftFast(const MachineInstr &MI) const;
|
2017-04-08 11:30:15 +08:00
|
|
|
/// Returns true if the instruction has a shift by immediate that can be
|
|
|
|
/// executed in one cycle less.
|
2017-05-24 03:57:45 +08:00
|
|
|
bool isFalkorShiftExtFast(const MachineInstr &MI) const;
|
2017-03-18 06:26:55 +08:00
|
|
|
|
2017-07-29 10:55:46 +08:00
|
|
|
private:
|
2017-03-18 06:26:55 +08:00
|
|
|
/// \brief Sets the offsets on outlined instructions in \p MBB which use SP
|
|
|
|
/// so that they will be valid post-outlining.
|
|
|
|
///
|
|
|
|
/// \param MBB A \p MachineBasicBlock in an outlined function.
|
|
|
|
void fixupPostOutline(MachineBasicBlock &MBB) const;
|
|
|
|
|
2016-06-12 23:39:02 +08:00
|
|
|
void instantiateCondBranch(MachineBasicBlock &MBB, const DebugLoc &DL,
|
2014-03-29 18:18:08 +08:00
|
|
|
MachineBasicBlock *TBB,
|
2015-06-12 03:30:37 +08:00
|
|
|
ArrayRef<MachineOperand> Cond) const;
|
2016-06-30 08:01:54 +08:00
|
|
|
bool substituteCmpToZero(MachineInstr &CmpInstr, unsigned SrcReg,
|
|
|
|
const MachineRegisterInfo *MRI) const;
|
2014-03-29 18:18:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// emitFrameOffset - Emit instructions as needed to set DestReg to SrcReg
|
|
|
|
/// plus Offset. This is intended to be used from within the prolog/epilog
|
|
|
|
/// insertion (PEI) pass, where a virtual scratch register may be allocated
|
|
|
|
/// if necessary, to be replaced by the scavenger at the end of PEI.
|
|
|
|
void emitFrameOffset(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
|
2016-06-12 23:39:02 +08:00
|
|
|
const DebugLoc &DL, unsigned DestReg, unsigned SrcReg,
|
|
|
|
int Offset, const TargetInstrInfo *TII,
|
2014-03-29 18:18:08 +08:00
|
|
|
MachineInstr::MIFlag = MachineInstr::NoFlags,
|
2014-04-30 21:14:14 +08:00
|
|
|
bool SetNZCV = false);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
/// rewriteAArch64FrameIndex - Rewrite MI to access 'Offset' bytes from the
|
2014-03-29 18:18:08 +08:00
|
|
|
/// FP. Return false if the offset could not be handled directly in MI, and
|
|
|
|
/// return the left-over portion by reference.
|
2014-05-24 20:50:23 +08:00
|
|
|
bool rewriteAArch64FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
|
2017-07-29 10:55:46 +08:00
|
|
|
unsigned FrameReg, int &Offset,
|
|
|
|
const AArch64InstrInfo *TII);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
/// \brief Use to report the frame offset status in isAArch64FrameOffsetLegal.
|
|
|
|
enum AArch64FrameOffsetStatus {
|
|
|
|
AArch64FrameOffsetCannotUpdate = 0x0, ///< Offset cannot apply.
|
|
|
|
AArch64FrameOffsetIsLegal = 0x1, ///< Offset is legal.
|
|
|
|
AArch64FrameOffsetCanUpdate = 0x2 ///< Offset can apply, at least partly.
|
2014-03-29 18:18:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Check if the @p Offset is a valid frame offset for @p MI.
|
|
|
|
/// The returned value reports the validity of the frame offset for @p MI.
|
2014-05-24 20:50:23 +08:00
|
|
|
/// It uses the values defined by AArch64FrameOffsetStatus for that.
|
|
|
|
/// If result == AArch64FrameOffsetCannotUpdate, @p MI cannot be updated to
|
2014-03-29 18:18:08 +08:00
|
|
|
/// use an offset.eq
|
2014-05-24 20:50:23 +08:00
|
|
|
/// If result & AArch64FrameOffsetIsLegal, @p Offset can completely be
|
2017-07-16 15:48:48 +08:00
|
|
|
/// rewritten in @p MI.
|
2014-05-24 20:50:23 +08:00
|
|
|
/// If result & AArch64FrameOffsetCanUpdate, @p Offset contains the
|
2014-03-29 18:18:08 +08:00
|
|
|
/// amount that is off the limit of the legal offset.
|
|
|
|
/// If set, @p OutUseUnscaledOp will contain the whether @p MI should be
|
|
|
|
/// turned into an unscaled operator, which opcode is in @p OutUnscaledOp.
|
|
|
|
/// If set, @p EmittableOffset contains the amount that can be set in @p MI
|
|
|
|
/// (possibly with @p OutUnscaledOp if OutUseUnscaledOp is true) and that
|
|
|
|
/// is a legal offset.
|
2014-05-24 20:50:23 +08:00
|
|
|
int isAArch64FrameOffsetLegal(const MachineInstr &MI, int &Offset,
|
2017-07-29 10:55:46 +08:00
|
|
|
bool *OutUseUnscaledOp = nullptr,
|
|
|
|
unsigned *OutUnscaledOp = nullptr,
|
|
|
|
int *EmittableOffset = nullptr);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
static inline bool isUncondBranchOpcode(int Opc) { return Opc == AArch64::B; }
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
static inline bool isCondBranchOpcode(int Opc) {
|
|
|
|
switch (Opc) {
|
2014-05-24 20:50:23 +08:00
|
|
|
case AArch64::Bcc:
|
|
|
|
case AArch64::CBZW:
|
|
|
|
case AArch64::CBZX:
|
|
|
|
case AArch64::CBNZW:
|
|
|
|
case AArch64::CBNZX:
|
|
|
|
case AArch64::TBZW:
|
|
|
|
case AArch64::TBZX:
|
|
|
|
case AArch64::TBNZW:
|
|
|
|
case AArch64::TBNZX:
|
2014-03-29 18:18:08 +08:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-29 10:55:46 +08:00
|
|
|
static inline bool isIndirectBranchOpcode(int Opc) {
|
|
|
|
return Opc == AArch64::BR;
|
|
|
|
}
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|