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"
|
2015-01-14 19:23:27 +08:00
|
|
|
#include "llvm/Target/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
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
class AArch64InstrInfo : public AArch64GenInstrInfo {
|
2014-03-29 18:18:08 +08:00
|
|
|
// Reserve bits in the MachineMemOperand target hint flags, starting at 1.
|
|
|
|
// They will be shifted into MOTargetHintStart when accessed.
|
|
|
|
enum TargetMemOperandFlags {
|
|
|
|
MOSuppressPair = 1
|
|
|
|
};
|
|
|
|
|
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; }
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
|
|
|
|
|
2014-07-29 10:09:26 +08:00
|
|
|
bool isAsCheapAsAMove(const MachineInstr *MI) const override;
|
|
|
|
|
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
|
|
|
|
areMemAccessesTriviallyDisjoint(MachineInstr *MIa, MachineInstr *MIb,
|
|
|
|
AliasAnalysis *AA = nullptr) const override;
|
|
|
|
|
2014-03-30 15:25:18 +08:00
|
|
|
unsigned isLoadFromStackSlot(const MachineInstr *MI,
|
|
|
|
int &FrameIndex) const override;
|
|
|
|
unsigned isStoreToStackSlot(const MachineInstr *MI,
|
|
|
|
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.
|
|
|
|
bool hasShiftedReg(const MachineInstr *MI) const;
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
/// Returns true if there is an extendable register and that the extending
|
|
|
|
/// value is non-zero.
|
2014-05-20 06:59:51 +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?
|
|
|
|
bool isGPRZero(const MachineInstr *MI) const;
|
|
|
|
|
|
|
|
/// \brief Does this instruction rename a GPR without modifying bits?
|
|
|
|
bool isGPRCopy(const MachineInstr *MI) const;
|
|
|
|
|
|
|
|
/// \brief Does this instruction rename an FPR without modifying bits?
|
|
|
|
bool isFPRCopy(const MachineInstr *MI) const;
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
bool isScaledAddr(const MachineInstr *MI) const;
|
|
|
|
|
|
|
|
/// Return true if pairing the given load or store is hinted to be
|
|
|
|
/// unprofitable.
|
|
|
|
bool isLdStPairSuppressed(const MachineInstr *MI) const;
|
|
|
|
|
|
|
|
/// Hint that pairing the given load or store is unprofitable.
|
|
|
|
void suppressLdStPair(MachineInstr *MI) const;
|
|
|
|
|
2015-06-16 02:44:14 +08:00
|
|
|
bool getMemOpBaseRegImmOfs(MachineInstr *LdSt, unsigned &BaseReg,
|
|
|
|
unsigned &Offset,
|
|
|
|
const TargetRegisterInfo *TRI) const override;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2015-06-16 02:44:14 +08:00
|
|
|
bool getMemOpBaseRegImmOfsWidth(MachineInstr *LdSt, unsigned &BaseReg,
|
|
|
|
int &Offset, int &Width,
|
|
|
|
const TargetRegisterInfo *TRI) const;
|
2014-09-08 22:43:48 +08:00
|
|
|
|
2014-03-30 15:25:18 +08:00
|
|
|
bool enableClusterLoads() const override { return true; }
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-03-30 15:25:18 +08:00
|
|
|
bool shouldClusterLoads(MachineInstr *FirstLdSt, MachineInstr *SecondLdSt,
|
|
|
|
unsigned NumLoads) const override;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-03-30 15:25:18 +08:00
|
|
|
bool shouldScheduleAdjacent(MachineInstr *First,
|
|
|
|
MachineInstr *Second) const override;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF, int FrameIx,
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
uint64_t Offset, const MDNode *Var,
|
|
|
|
const MDNode *Expr, DebugLoc DL) const;
|
2014-03-29 18:18:08 +08:00
|
|
|
void copyPhysRegTuple(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
|
|
|
|
DebugLoc DL, unsigned DestReg, unsigned SrcReg,
|
|
|
|
bool KillSrc, unsigned Opcode,
|
|
|
|
llvm::ArrayRef<unsigned> Indices) const;
|
2014-03-30 15:25:18 +08:00
|
|
|
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
|
|
|
|
DebugLoc DL, unsigned DestReg, unsigned SrcReg,
|
|
|
|
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;
|
|
|
|
|
2014-07-31 20:58:50 +08:00
|
|
|
using TargetInstrInfo::foldMemoryOperandImpl;
|
2015-02-28 20:04:00 +08:00
|
|
|
MachineInstr *foldMemoryOperandImpl(MachineFunction &MF, MachineInstr *MI,
|
|
|
|
ArrayRef<unsigned> Ops,
|
2015-06-09 04:09:58 +08:00
|
|
|
MachineBasicBlock::iterator InsertPt,
|
2015-02-28 20:04:00 +08:00
|
|
|
int FrameIndex) const override;
|
2014-03-30 15:25:18 +08:00
|
|
|
|
|
|
|
bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
|
|
|
|
MachineBasicBlock *&FBB,
|
|
|
|
SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
bool AllowModify = false) const override;
|
|
|
|
unsigned RemoveBranch(MachineBasicBlock &MBB) const override;
|
|
|
|
unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
|
2015-06-12 03:30:37 +08:00
|
|
|
MachineBasicBlock *FBB, ArrayRef<MachineOperand> Cond,
|
2014-03-30 15:25:18 +08:00
|
|
|
DebugLoc DL) const override;
|
|
|
|
bool
|
|
|
|
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,
|
2015-06-12 03:30:37 +08:00
|
|
|
DebugLoc DL, unsigned DstReg, ArrayRef<MachineOperand> Cond,
|
2014-03-30 15:25:18 +08:00
|
|
|
unsigned TrueReg, unsigned FalseReg) const override;
|
|
|
|
void getNoopForMachoTarget(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.
|
2014-03-30 15:25:18 +08:00
|
|
|
bool analyzeCompare(const MachineInstr *MI, unsigned &SrcReg,
|
|
|
|
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.
|
2014-03-30 15:25:18 +08:00
|
|
|
bool optimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg,
|
|
|
|
unsigned SrcReg2, int CmpMask, int CmpValue,
|
|
|
|
const MachineRegisterInfo *MRI) const override;
|
2014-10-28 07:29:27 +08:00
|
|
|
bool optimizeCondBranch(MachineInstr *MI) const override;
|
2015-06-20 07:21:42 +08:00
|
|
|
/// Return true when there is potentially a faster code sequence
|
2014-08-08 05:40:58 +08:00
|
|
|
/// for an instruction chain ending in <Root>. All potential patterns are
|
2015-06-20 07:21:42 +08:00
|
|
|
/// listed in the <Patterns> array.
|
|
|
|
bool getMachineCombinerPatterns(MachineInstr &Root,
|
|
|
|
SmallVectorImpl<MachineCombinerPattern::MC_PATTERN> &Patterns)
|
2014-09-03 19:41:21 +08:00
|
|
|
const override;
|
2014-08-08 05:40:58 +08:00
|
|
|
|
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-06-20 07:21:42 +08:00
|
|
|
MachineInstr &Root, MachineCombinerPattern::MC_PATTERN 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;
|
2014-08-08 05:40:58 +08:00
|
|
|
/// useMachineCombiner - AArch64 supports MachineCombiner
|
2014-09-03 19:41:21 +08:00
|
|
|
bool useMachineCombiner() const override;
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-07-26 03:31:34 +08:00
|
|
|
bool expandPostRAPseudo(MachineBasicBlock::iterator 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;
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
private:
|
|
|
|
void instantiateCondBranch(MachineBasicBlock &MBB, DebugLoc DL,
|
|
|
|
MachineBasicBlock *TBB,
|
2015-06-12 03:30:37 +08:00
|
|
|
ArrayRef<MachineOperand> Cond) 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,
|
|
|
|
DebugLoc DL, unsigned DestReg, unsigned SrcReg, int Offset,
|
2014-06-11 01:33:39 +08:00
|
|
|
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,
|
2014-03-29 18:18:08 +08:00
|
|
|
unsigned FrameReg, int &Offset,
|
2014-05-24 20:50:23 +08:00
|
|
|
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
|
2014-03-29 18:18:08 +08:00
|
|
|
/// rewriten 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,
|
2014-04-28 12:05:08 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
static inline bool isIndirectBranchOpcode(int Opc) { return Opc == AArch64::BR; }
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|