2012-02-18 12:03:15 +00:00
|
|
|
//===-- X86InstrInfo.h - X86 Instruction Information ------------*- C++ -*-===//
|
2005-04-21 23:38:14 +00:00
|
|
|
//
|
2003-10-21 15:17:13 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 23:38:14 +00:00
|
|
|
//
|
2003-10-21 15:17:13 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-10-25 22:55:53 +00:00
|
|
|
//
|
2003-01-14 22:00:31 +00:00
|
|
|
// This file contains the X86 implementation of the TargetInstrInfo class.
|
2002-10-25 22:55:53 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef X86INSTRUCTIONINFO_H
|
|
|
|
#define X86INSTRUCTIONINFO_H
|
|
|
|
|
2014-03-19 06:53:25 +00:00
|
|
|
#include "MCTargetDesc/X86BaseInfo.h"
|
2002-10-25 22:55:53 +00:00
|
|
|
#include "X86RegisterInfo.h"
|
2009-01-05 17:59:02 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2012-03-17 18:46:09 +00:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2002-10-25 22:55:53 +00:00
|
|
|
|
2011-07-01 17:57:27 +00:00
|
|
|
#define GET_INSTRINFO_HEADER
|
|
|
|
#include "X86GenInstrInfo.inc"
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
2006-09-08 06:48:29 +00:00
|
|
|
class X86RegisterInfo;
|
2006-05-30 21:45:53 +00:00
|
|
|
class X86TargetMachine;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2006-10-20 17:42:20 +00:00
|
|
|
namespace X86 {
|
|
|
|
// X86 specific condition code. These correspond to X86_*_COND in
|
|
|
|
// X86InstrInfo.td. They must be kept in synch.
|
|
|
|
enum CondCode {
|
|
|
|
COND_A = 0,
|
|
|
|
COND_AE = 1,
|
|
|
|
COND_B = 2,
|
|
|
|
COND_BE = 3,
|
|
|
|
COND_E = 4,
|
|
|
|
COND_G = 5,
|
|
|
|
COND_GE = 6,
|
|
|
|
COND_L = 7,
|
|
|
|
COND_LE = 8,
|
|
|
|
COND_NE = 9,
|
|
|
|
COND_NO = 10,
|
|
|
|
COND_NP = 11,
|
|
|
|
COND_NS = 12,
|
2009-01-07 00:15:08 +00:00
|
|
|
COND_O = 13,
|
|
|
|
COND_P = 14,
|
|
|
|
COND_S = 15,
|
Optimized FCMP_OEQ and FCMP_UNE for x86.
Where previously LLVM might emit code like this:
ucomisd %xmm1, %xmm0
setne %al
setp %cl
orb %al, %cl
jne .LBB4_2
it now emits this:
ucomisd %xmm1, %xmm0
jne .LBB4_2
jp .LBB4_2
It has fewer instructions and uses fewer registers, but it does
have more branches. And in the case that this code is followed by
a non-fallthrough edge, it may be followed by a jmp instruction,
resulting in three branch instructions in sequence. Some effort
is made to avoid this situation.
To achieve this, X86ISelLowering.cpp now recognizes FCMP_OEQ and
FCMP_UNE in lowered form, and replace them with code that emits
two branches, except in the case where it would require converting
a fall-through edge to an explicit branch.
Also, X86InstrInfo.cpp's branch analysis and transform code now
knows now to handle blocks with multiple conditional branches. It
uses loops instead of having fixed checks for up to two
instructions. It can now analyze and transform code generated
from FCMP_OEQ and FCMP_UNE.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57873 91177308-0d34-0410-b5e6-96231b3b80d8
2008-10-21 03:29:32 +00:00
|
|
|
|
|
|
|
// Artificial condition codes. These are used by AnalyzeBranch
|
|
|
|
// to indicate a block terminated with two conditional branches to
|
|
|
|
// the same location. This occurs in code using FCMP_OEQ or FCMP_UNE,
|
|
|
|
// which can't be represented on x86 with a single condition. These
|
|
|
|
// are never used in MachineInstrs.
|
|
|
|
COND_NE_OR_P,
|
|
|
|
COND_NP_OR_E,
|
|
|
|
|
2006-10-20 17:42:20 +00:00
|
|
|
COND_INVALID
|
|
|
|
};
|
2011-03-05 06:31:54 +00:00
|
|
|
|
2006-10-20 17:42:20 +00:00
|
|
|
// Turn condition code into conditional branch opcode.
|
|
|
|
unsigned GetCondBranchFromCond(CondCode CC);
|
2011-03-05 06:31:54 +00:00
|
|
|
|
2012-09-20 03:06:15 +00:00
|
|
|
// Turn CMov opcode into condition code.
|
|
|
|
CondCode getCondFromCMovOpc(unsigned Opc);
|
|
|
|
|
2006-10-21 05:52:40 +00:00
|
|
|
/// GetOppositeBranchCondition - Return the inverse of the specified cond,
|
|
|
|
/// e.g. turning COND_E to COND_NE.
|
|
|
|
CondCode GetOppositeBranchCondition(X86::CondCode CC);
|
2011-07-25 18:43:53 +00:00
|
|
|
} // end namespace X86;
|
2006-10-21 05:52:40 +00:00
|
|
|
|
2009-07-10 06:06:17 +00:00
|
|
|
|
2009-07-10 06:29:59 +00:00
|
|
|
/// isGlobalStubReference - Return true if the specified TargetFlag operand is
|
2009-07-10 06:06:17 +00:00
|
|
|
/// a reference to a stub for a global, not the global itself.
|
2009-07-10 06:29:59 +00:00
|
|
|
inline static bool isGlobalStubReference(unsigned char TargetFlag) {
|
|
|
|
switch (TargetFlag) {
|
2009-07-10 06:06:17 +00:00
|
|
|
case X86II::MO_DLLIMPORT: // dllimport stub.
|
|
|
|
case X86II::MO_GOTPCREL: // rip-relative GOT reference.
|
|
|
|
case X86II::MO_GOT: // normal GOT reference.
|
|
|
|
case X86II::MO_DARWIN_NONLAZY_PIC_BASE: // Normal $non_lazy_ptr ref.
|
|
|
|
case X86II::MO_DARWIN_NONLAZY: // Normal $non_lazy_ptr ref.
|
|
|
|
case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: // Hidden $non_lazy_ptr ref.
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2009-07-10 07:33:30 +00:00
|
|
|
|
|
|
|
/// isGlobalRelativeToPICBase - Return true if the specified global value
|
|
|
|
/// reference is relative to a 32-bit PIC base (X86ISD::GlobalBaseReg). If this
|
|
|
|
/// is true, the addressing mode has the PIC base register added in (e.g. EBX).
|
|
|
|
inline static bool isGlobalRelativeToPICBase(unsigned char TargetFlag) {
|
|
|
|
switch (TargetFlag) {
|
|
|
|
case X86II::MO_GOTOFF: // isPICStyleGOT: local global.
|
|
|
|
case X86II::MO_GOT: // isPICStyleGOT: other global.
|
|
|
|
case X86II::MO_PIC_BASE_OFFSET: // Darwin local global.
|
|
|
|
case X86II::MO_DARWIN_NONLAZY_PIC_BASE: // Darwin/32 external global.
|
|
|
|
case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: // Darwin/32 hidden global.
|
2010-06-03 04:07:48 +00:00
|
|
|
case X86II::MO_TLVP: // ??? Pretty sure..
|
2009-07-10 07:33:30 +00:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2011-03-05 06:31:54 +00:00
|
|
|
|
2008-06-28 11:07:54 +00:00
|
|
|
inline static bool isScale(const MachineOperand &MO) {
|
2008-10-03 15:45:36 +00:00
|
|
|
return MO.isImm() &&
|
2008-06-28 11:07:54 +00:00
|
|
|
(MO.getImm() == 1 || MO.getImm() == 2 ||
|
|
|
|
MO.getImm() == 4 || MO.getImm() == 8);
|
|
|
|
}
|
|
|
|
|
2009-04-08 21:14:34 +00:00
|
|
|
inline static bool isLeaMem(const MachineInstr *MI, unsigned Op) {
|
2008-10-03 15:45:36 +00:00
|
|
|
if (MI->getOperand(Op).isFI()) return true;
|
2014-03-18 16:14:11 +00:00
|
|
|
return Op+X86::AddrSegmentReg <= MI->getNumOperands() &&
|
|
|
|
MI->getOperand(Op+X86::AddrBaseReg).isReg() &&
|
|
|
|
isScale(MI->getOperand(Op+X86::AddrScaleAmt)) &&
|
|
|
|
MI->getOperand(Op+X86::AddrIndexReg).isReg() &&
|
|
|
|
(MI->getOperand(Op+X86::AddrDisp).isImm() ||
|
|
|
|
MI->getOperand(Op+X86::AddrDisp).isGlobal() ||
|
|
|
|
MI->getOperand(Op+X86::AddrDisp).isCPI() ||
|
|
|
|
MI->getOperand(Op+X86::AddrDisp).isJTI());
|
2008-06-28 11:07:54 +00:00
|
|
|
}
|
|
|
|
|
2009-04-08 21:14:34 +00:00
|
|
|
inline static bool isMem(const MachineInstr *MI, unsigned Op) {
|
|
|
|
if (MI->getOperand(Op).isFI()) return true;
|
2014-03-18 16:14:11 +00:00
|
|
|
return Op+X86::AddrNumOperands <= MI->getNumOperands() &&
|
|
|
|
MI->getOperand(Op+X86::AddrSegmentReg).isReg() &&
|
2009-04-08 21:14:34 +00:00
|
|
|
isLeaMem(MI, Op);
|
|
|
|
}
|
|
|
|
|
2014-03-31 06:53:13 +00:00
|
|
|
class X86InstrInfo final : public X86GenInstrInfo {
|
2006-05-30 21:45:53 +00:00
|
|
|
X86TargetMachine &TM;
|
2002-10-25 22:55:53 +00:00
|
|
|
const X86RegisterInfo RI;
|
2011-03-05 06:31:54 +00:00
|
|
|
|
2012-06-01 05:34:01 +00:00
|
|
|
/// RegOp2MemOpTable3Addr, RegOp2MemOpTable0, RegOp2MemOpTable1,
|
|
|
|
/// RegOp2MemOpTable2, RegOp2MemOpTable3 - Load / store folding opcode maps.
|
2008-01-07 01:35:02 +00:00
|
|
|
///
|
* Combines Alignment, AuxInfo, and TB_NOT_REVERSABLE flag into a
single field (Flags), which is a bitwise OR of items from the TB_*
enum. This makes it easier to add new information in the future.
* Gives every static array an equivalent layout: { RegOp, MemOp, Flags }
* Adds a helper function, AddTableEntry, to avoid duplication of the
insertion code.
* Renames TB_NOT_REVERSABLE to TB_NO_REVERSE.
* Adds TB_NO_FORWARD, which is analogous to TB_NO_REVERSE, except that
it prevents addition of the Reg->Mem entry. (This is going to be used
by Native Client, in the next CL).
Patch by David Meyer
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139311 91177308-0d34-0410-b5e6-96231b3b80d8
2011-09-08 18:35:57 +00:00
|
|
|
typedef DenseMap<unsigned,
|
|
|
|
std::pair<unsigned, unsigned> > RegOp2MemOpTableType;
|
|
|
|
RegOp2MemOpTableType RegOp2MemOpTable2Addr;
|
|
|
|
RegOp2MemOpTableType RegOp2MemOpTable0;
|
|
|
|
RegOp2MemOpTableType RegOp2MemOpTable1;
|
|
|
|
RegOp2MemOpTableType RegOp2MemOpTable2;
|
2012-05-31 09:20:20 +00:00
|
|
|
RegOp2MemOpTableType RegOp2MemOpTable3;
|
2011-03-05 06:31:54 +00:00
|
|
|
|
2008-01-07 01:35:02 +00:00
|
|
|
/// MemOp2RegOpTable - Load / store unfolding opcode map.
|
|
|
|
///
|
* Combines Alignment, AuxInfo, and TB_NOT_REVERSABLE flag into a
single field (Flags), which is a bitwise OR of items from the TB_*
enum. This makes it easier to add new information in the future.
* Gives every static array an equivalent layout: { RegOp, MemOp, Flags }
* Adds a helper function, AddTableEntry, to avoid duplication of the
insertion code.
* Renames TB_NOT_REVERSABLE to TB_NO_REVERSE.
* Adds TB_NO_FORWARD, which is analogous to TB_NO_REVERSE, except that
it prevents addition of the Reg->Mem entry. (This is going to be used
by Native Client, in the next CL).
Patch by David Meyer
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139311 91177308-0d34-0410-b5e6-96231b3b80d8
2011-09-08 18:35:57 +00:00
|
|
|
typedef DenseMap<unsigned,
|
|
|
|
std::pair<unsigned, unsigned> > MemOp2RegOpTableType;
|
|
|
|
MemOp2RegOpTableType MemOp2RegOpTable;
|
|
|
|
|
2012-06-23 04:58:41 +00:00
|
|
|
static void AddTableEntry(RegOp2MemOpTableType &R2MTable,
|
|
|
|
MemOp2RegOpTableType &M2RTable,
|
|
|
|
unsigned RegOp, unsigned MemOp, unsigned Flags);
|
2010-03-25 17:25:00 +00:00
|
|
|
|
2013-11-19 00:57:56 +00:00
|
|
|
virtual void anchor();
|
|
|
|
|
2002-10-25 22:55:53 +00:00
|
|
|
public:
|
2008-03-25 22:06:05 +00:00
|
|
|
explicit X86InstrInfo(X86TargetMachine &tm);
|
2002-10-25 22:55:53 +00:00
|
|
|
|
2003-01-14 22:00:31 +00:00
|
|
|
/// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
|
2002-10-25 22:55:53 +00:00
|
|
|
/// such, whenever a client has an instance of instruction info, it should
|
|
|
|
/// always be able to get register info as well (through this method).
|
|
|
|
///
|
2014-03-09 07:58:15 +00:00
|
|
|
const X86RegisterInfo &getRegisterInfo() const { return RI; }
|
2002-10-25 22:55:53 +00:00
|
|
|
|
2010-01-13 00:30:23 +00:00
|
|
|
/// isCoalescableExtInstr - Return true if the instruction is a "coalescable"
|
|
|
|
/// extension instruction. That is, it's like a copy where it's legal for the
|
|
|
|
/// source to overlap the destination. e.g. X86::MOVSX64rr32. If this returns
|
|
|
|
/// true, then it's expected the pre-extension value is available as a subreg
|
|
|
|
/// of the result register. This also returns the sub-register index in
|
|
|
|
/// SubIdx.
|
2014-03-09 07:44:38 +00:00
|
|
|
bool isCoalescableExtInstr(const MachineInstr &MI,
|
|
|
|
unsigned &SrcReg, unsigned &DstReg,
|
|
|
|
unsigned &SubIdx) const override;
|
2010-01-12 00:09:37 +00:00
|
|
|
|
2014-03-09 07:44:38 +00:00
|
|
|
unsigned isLoadFromStackSlot(const MachineInstr *MI,
|
|
|
|
int &FrameIndex) const override;
|
2009-11-13 00:29:53 +00:00
|
|
|
/// isLoadFromStackSlotPostFE - Check for post-frame ptr elimination
|
|
|
|
/// stack locations as well. This uses a heuristic so it isn't
|
|
|
|
/// reliable for correctness.
|
|
|
|
unsigned isLoadFromStackSlotPostFE(const MachineInstr *MI,
|
2014-03-09 07:44:38 +00:00
|
|
|
int &FrameIndex) const override;
|
2009-11-12 20:55:29 +00:00
|
|
|
|
2014-03-09 07:44:38 +00:00
|
|
|
unsigned isStoreToStackSlot(const MachineInstr *MI,
|
|
|
|
int &FrameIndex) const override;
|
2009-11-13 00:29:53 +00:00
|
|
|
/// isStoreToStackSlotPostFE - Check for post-frame ptr elimination
|
|
|
|
/// stack locations as well. This uses a heuristic so it isn't
|
|
|
|
/// reliable for correctness.
|
|
|
|
unsigned isStoreToStackSlotPostFE(const MachineInstr *MI,
|
2014-03-09 07:44:38 +00:00
|
|
|
int &FrameIndex) const override;
|
2008-03-31 20:40:39 +00:00
|
|
|
|
2009-10-10 00:34:18 +00:00
|
|
|
bool isReallyTriviallyReMaterializable(const MachineInstr *MI,
|
2014-03-09 07:44:38 +00:00
|
|
|
AliasAnalysis *AA) const override;
|
2008-03-31 20:40:39 +00:00
|
|
|
void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
|
2009-07-16 09:20:10 +00:00
|
|
|
unsigned DestReg, unsigned SubIdx,
|
2009-11-14 02:55:43 +00:00
|
|
|
const MachineInstr *Orig,
|
2014-03-09 07:44:38 +00:00
|
|
|
const TargetRegisterInfo &TRI) const override;
|
2008-03-31 20:40:39 +00:00
|
|
|
|
2013-06-10 20:43:49 +00:00
|
|
|
/// Given an operand within a MachineInstr, insert preceding code to put it
|
|
|
|
/// into the right format for a particular kind of LEA instruction. This may
|
|
|
|
/// involve using an appropriate super-register instead (with an implicit use
|
|
|
|
/// of the original) or creating a new virtual register and inserting COPY
|
|
|
|
/// instructions to get the data into the right class.
|
|
|
|
///
|
|
|
|
/// Reference parameters are set to indicate how caller should add this
|
|
|
|
/// operand to the LEA instruction.
|
|
|
|
bool classifyLEAReg(MachineInstr *MI, const MachineOperand &Src,
|
|
|
|
unsigned LEAOpcode, bool AllowSP,
|
|
|
|
unsigned &NewSrc, bool &isKill,
|
|
|
|
bool &isUndef, MachineOperand &ImplicitOp) const;
|
|
|
|
|
2005-01-02 02:37:07 +00:00
|
|
|
/// convertToThreeAddress - This method must be implemented by targets that
|
|
|
|
/// set the M_CONVERTIBLE_TO_3_ADDR flag. When this flag is set, the target
|
|
|
|
/// may be able to convert a two-address instruction into a true
|
|
|
|
/// three-address instruction on demand. This allows the X86 target (for
|
|
|
|
/// example) to convert ADD and SHL instructions into LEA instructions if they
|
|
|
|
/// would require register copies due to two-addressness.
|
|
|
|
///
|
|
|
|
/// This method returns a null pointer if the transformation cannot be
|
|
|
|
/// performed, otherwise it returns the new instruction.
|
|
|
|
///
|
2014-03-09 07:44:38 +00:00
|
|
|
MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
|
|
|
|
MachineBasicBlock::iterator &MBBI,
|
|
|
|
LiveVariables *LV) const override;
|
2005-01-02 02:37:07 +00:00
|
|
|
|
Teach the code generator that shrd/shld is commutable if it has an immediate.
This allows us to generate this:
foo:
mov %EAX, DWORD PTR [%ESP + 4]
mov %EDX, DWORD PTR [%ESP + 8]
shld %EDX, %EDX, 2
shl %EAX, 2
ret
instead of this:
foo:
mov %EAX, DWORD PTR [%ESP + 4]
mov %ECX, DWORD PTR [%ESP + 8]
mov %EDX, %EAX
shrd %EDX, %ECX, 30
shl %EAX, 2
ret
Note the magically transmogrifying immediate.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19686 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-19 07:11:01 +00:00
|
|
|
/// commuteInstruction - We have a few instructions that must be hacked on to
|
|
|
|
/// commute them.
|
|
|
|
///
|
2014-03-09 07:44:38 +00:00
|
|
|
MachineInstr *commuteInstruction(MachineInstr *MI, bool NewMI) const override;
|
Teach the code generator that shrd/shld is commutable if it has an immediate.
This allows us to generate this:
foo:
mov %EAX, DWORD PTR [%ESP + 4]
mov %EDX, DWORD PTR [%ESP + 8]
shld %EDX, %EDX, 2
shl %EAX, 2
ret
instead of this:
foo:
mov %EAX, DWORD PTR [%ESP + 4]
mov %ECX, DWORD PTR [%ESP + 8]
mov %EDX, %EAX
shrd %EDX, %ECX, 30
shl %EAX, 2
ret
Note the magically transmogrifying immediate.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19686 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-19 07:11:01 +00:00
|
|
|
|
2014-04-02 23:57:49 +00:00
|
|
|
bool findCommutedOpIndices(MachineInstr *MI, unsigned &SrcOpIdx1,
|
|
|
|
unsigned &SrcOpIdx2) const override;
|
|
|
|
|
2006-10-20 17:42:20 +00:00
|
|
|
// Branch analysis.
|
2014-03-09 07:44:38 +00:00
|
|
|
bool isUnpredicatedTerminator(const MachineInstr* MI) const override;
|
|
|
|
bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
|
|
|
|
MachineBasicBlock *&FBB,
|
|
|
|
SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
bool AllowModify) const override;
|
|
|
|
unsigned RemoveBranch(MachineBasicBlock &MBB) const override;
|
|
|
|
unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
|
|
|
|
MachineBasicBlock *FBB,
|
|
|
|
const SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
DebugLoc DL) const override;
|
|
|
|
bool canInsertSelect(const MachineBasicBlock&,
|
|
|
|
const SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
unsigned, unsigned, int&, int&, int&) const override;
|
|
|
|
void insertSelect(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI, DebugLoc DL,
|
|
|
|
unsigned DstReg,
|
|
|
|
const SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
unsigned TrueReg, unsigned FalseReg) const override;
|
|
|
|
void copyPhysReg(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI, DebugLoc DL,
|
|
|
|
unsigned DestReg, unsigned SrcReg,
|
|
|
|
bool KillSrc) const override;
|
|
|
|
void storeRegToStackSlot(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned SrcReg, bool isKill, int FrameIndex,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
const TargetRegisterInfo *TRI) const override;
|
2008-01-01 21:11:32 +00:00
|
|
|
|
2014-03-09 07:58:15 +00:00
|
|
|
void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
|
|
|
|
SmallVectorImpl<MachineOperand> &Addr,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
MachineInstr::mmo_iterator MMOBegin,
|
|
|
|
MachineInstr::mmo_iterator MMOEnd,
|
|
|
|
SmallVectorImpl<MachineInstr*> &NewMIs) const;
|
2008-01-01 21:11:32 +00:00
|
|
|
|
2014-03-09 07:44:38 +00:00
|
|
|
void loadRegFromStackSlot(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned DestReg, int FrameIndex,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
const TargetRegisterInfo *TRI) const override;
|
2008-01-01 21:11:32 +00:00
|
|
|
|
2014-03-09 07:58:15 +00:00
|
|
|
void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
|
|
|
|
SmallVectorImpl<MachineOperand> &Addr,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
MachineInstr::mmo_iterator MMOBegin,
|
|
|
|
MachineInstr::mmo_iterator MMOEnd,
|
|
|
|
SmallVectorImpl<MachineInstr*> &NewMIs) const;
|
2011-09-29 05:10:54 +00:00
|
|
|
|
2014-03-09 07:44:38 +00:00
|
|
|
bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override;
|
2011-09-29 05:10:54 +00:00
|
|
|
|
2008-01-07 01:35:02 +00:00
|
|
|
/// foldMemoryOperand - If this target supports it, fold a load or store of
|
|
|
|
/// the specified stack slot into the specified machine instruction for the
|
|
|
|
/// specified operand(s). If this is possible, the target should perform the
|
|
|
|
/// folding and return true, otherwise it should return false. If it folds
|
|
|
|
/// the instruction, it is likely that the MachineInstruction the iterator
|
|
|
|
/// references has been changed.
|
2014-03-09 07:44:38 +00:00
|
|
|
MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
|
|
|
|
MachineInstr* MI,
|
|
|
|
const SmallVectorImpl<unsigned> &Ops,
|
|
|
|
int FrameIndex) const override;
|
2008-01-07 01:35:02 +00:00
|
|
|
|
|
|
|
/// foldMemoryOperand - Same as the previous version except it allows folding
|
|
|
|
/// of any load and store from / to any address, not just from a specific
|
|
|
|
/// stack slot.
|
2014-03-09 07:44:38 +00:00
|
|
|
MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
|
|
|
|
MachineInstr* MI,
|
|
|
|
const SmallVectorImpl<unsigned> &Ops,
|
|
|
|
MachineInstr* LoadMI) const override;
|
2008-01-07 01:35:02 +00:00
|
|
|
|
|
|
|
/// canFoldMemoryOperand - Returns true if the specified load / store is
|
|
|
|
/// folding is possible.
|
2014-03-09 07:44:38 +00:00
|
|
|
bool canFoldMemoryOperand(const MachineInstr*,
|
|
|
|
const SmallVectorImpl<unsigned> &) const override;
|
2008-01-07 01:35:02 +00:00
|
|
|
|
|
|
|
/// unfoldMemoryOperand - Separate a single instruction which folded a load or
|
|
|
|
/// a store or a load and a store into two or more instruction. If this is
|
|
|
|
/// possible, returns true as well as the new instructions by reference.
|
2014-03-09 07:44:38 +00:00
|
|
|
bool unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI,
|
|
|
|
unsigned Reg, bool UnfoldLoad, bool UnfoldStore,
|
|
|
|
SmallVectorImpl<MachineInstr*> &NewMIs) const override;
|
2008-01-07 01:35:02 +00:00
|
|
|
|
2014-03-09 07:44:38 +00:00
|
|
|
bool unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
|
|
|
|
SmallVectorImpl<SDNode*> &NewNodes) const override;
|
2008-01-07 01:35:02 +00:00
|
|
|
|
|
|
|
/// getOpcodeAfterMemoryUnfold - Returns the opcode of the would be new
|
|
|
|
/// instruction after load / store are unfolded from an instruction of the
|
|
|
|
/// specified opcode. It returns zero if the specified unfolding is not
|
2009-10-30 22:18:41 +00:00
|
|
|
/// possible. If LoadRegIndex is non-null, it is filled in with the operand
|
|
|
|
/// index of the operand which will hold the register holding the loaded
|
|
|
|
/// value.
|
2014-03-09 07:44:38 +00:00
|
|
|
unsigned getOpcodeAfterMemoryUnfold(unsigned Opc,
|
|
|
|
bool UnfoldLoad, bool UnfoldStore,
|
|
|
|
unsigned *LoadRegIndex = 0) const override;
|
2011-03-05 06:31:54 +00:00
|
|
|
|
2010-01-22 03:34:51 +00:00
|
|
|
/// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler
|
|
|
|
/// to determine if two loads are loading from the same base address. It
|
|
|
|
/// should only return true if the base pointers are the same and the
|
|
|
|
/// only differences between the two addresses are the offset. It also returns
|
|
|
|
/// the offsets by reference.
|
2014-03-09 07:44:38 +00:00
|
|
|
bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2, int64_t &Offset1,
|
|
|
|
int64_t &Offset2) const override;
|
2010-01-22 03:34:51 +00:00
|
|
|
|
|
|
|
/// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to
|
2011-04-15 05:18:47 +00:00
|
|
|
/// determine (in conjunction with areLoadsFromSameBasePtr) if two loads should
|
2010-01-22 03:34:51 +00:00
|
|
|
/// be scheduled togther. On some targets if two loads are loading from
|
|
|
|
/// addresses in the same cache line, it's better if they are scheduled
|
|
|
|
/// together. This function takes two integers that represent the load offsets
|
|
|
|
/// from the common base address. It returns true if it decides it's desirable
|
|
|
|
/// to schedule the two loads together. "NumLoads" is the number of loads that
|
|
|
|
/// have already been scheduled after Load1.
|
2014-03-09 07:44:38 +00:00
|
|
|
bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
|
|
|
|
int64_t Offset1, int64_t Offset2,
|
|
|
|
unsigned NumLoads) const override;
|
2010-01-22 03:34:51 +00:00
|
|
|
|
2014-03-09 07:44:38 +00:00
|
|
|
bool shouldScheduleAdjacent(MachineInstr* First,
|
|
|
|
MachineInstr *Second) const override;
|
2013-06-23 09:00:28 +00:00
|
|
|
|
2014-03-09 07:44:38 +00:00
|
|
|
void getNoopForMachoTarget(MCInst &NopInst) const override;
|
2010-04-26 23:37:21 +00:00
|
|
|
|
2014-03-09 07:44:38 +00:00
|
|
|
bool
|
|
|
|
ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
|
Teach the code generator that shrd/shld is commutable if it has an immediate.
This allows us to generate this:
foo:
mov %EAX, DWORD PTR [%ESP + 4]
mov %EDX, DWORD PTR [%ESP + 8]
shld %EDX, %EDX, 2
shl %EAX, 2
ret
instead of this:
foo:
mov %EAX, DWORD PTR [%ESP + 4]
mov %ECX, DWORD PTR [%ESP + 8]
mov %EDX, %EAX
shrd %EDX, %ECX, 30
shl %EAX, 2
ret
Note the magically transmogrifying immediate.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19686 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-19 07:11:01 +00:00
|
|
|
|
2009-02-06 17:17:30 +00:00
|
|
|
/// isSafeToMoveRegClassDefs - Return true if it's safe to move a machine
|
|
|
|
/// instruction that defines the specified register class.
|
2014-03-09 07:44:38 +00:00
|
|
|
bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const override;
|
2008-10-27 07:14:50 +00:00
|
|
|
|
2010-02-05 22:10:22 +00:00
|
|
|
static bool isX86_64ExtendedReg(const MachineOperand &MO) {
|
|
|
|
if (!MO.isReg()) return false;
|
2011-07-25 18:43:53 +00:00
|
|
|
return X86II::isX86_64ExtendedReg(MO.getReg());
|
2010-02-05 22:10:22 +00:00
|
|
|
}
|
2008-04-16 20:10:13 +00:00
|
|
|
|
2008-09-30 00:58:23 +00:00
|
|
|
/// getGlobalBaseReg - Return a virtual register initialized with the
|
|
|
|
/// the global base register value. Output instructions required to
|
|
|
|
/// initialize the register in the function entry block, if necessary.
|
2008-09-23 18:22:58 +00:00
|
|
|
///
|
2008-09-30 00:58:23 +00:00
|
|
|
unsigned getGlobalBaseReg(MachineFunction *MF) const;
|
2008-09-23 18:22:58 +00:00
|
|
|
|
2011-09-27 22:57:18 +00:00
|
|
|
std::pair<uint16_t, uint16_t>
|
2014-03-09 07:44:38 +00:00
|
|
|
getExecutionDomain(const MachineInstr *MI) const override;
|
2010-03-29 23:24:21 +00:00
|
|
|
|
2014-03-09 07:44:38 +00:00
|
|
|
void setExecutionDomain(MachineInstr *MI, unsigned Domain) const override;
|
2010-03-25 17:25:00 +00:00
|
|
|
|
2014-03-09 07:44:38 +00:00
|
|
|
unsigned
|
|
|
|
getPartialRegUpdateClearance(const MachineInstr *MI, unsigned OpNum,
|
|
|
|
const TargetRegisterInfo *TRI) const override;
|
2013-10-14 22:19:03 +00:00
|
|
|
unsigned getUndefRegClearance(const MachineInstr *MI, unsigned &OpNum,
|
2014-03-09 07:44:38 +00:00
|
|
|
const TargetRegisterInfo *TRI) const override;
|
2011-11-15 01:15:30 +00:00
|
|
|
void breakPartialRegDependency(MachineBasicBlock::iterator MI, unsigned OpNum,
|
2014-03-09 07:44:38 +00:00
|
|
|
const TargetRegisterInfo *TRI) const override;
|
2011-11-15 01:15:30 +00:00
|
|
|
|
implement rdar://6653118 - fastisel should fold loads where possible.
Since mem2reg isn't run at -O0, we get a ton of reloads from the stack,
for example, before, this code:
int foo(int x, int y, int z) {
return x+y+z;
}
used to compile into:
_foo: ## @foo
subq $12, %rsp
movl %edi, 8(%rsp)
movl %esi, 4(%rsp)
movl %edx, (%rsp)
movl 8(%rsp), %edx
movl 4(%rsp), %esi
addl %edx, %esi
movl (%rsp), %edx
addl %esi, %edx
movl %edx, %eax
addq $12, %rsp
ret
Now we produce:
_foo: ## @foo
subq $12, %rsp
movl %edi, 8(%rsp)
movl %esi, 4(%rsp)
movl %edx, (%rsp)
movl 8(%rsp), %edx
addl 4(%rsp), %edx ## Folded load
addl (%rsp), %edx ## Folded load
movl %edx, %eax
addq $12, %rsp
ret
Fewer instructions and less register use = faster compiles.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113102 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-05 02:18:34 +00:00
|
|
|
MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
|
|
|
|
MachineInstr* MI,
|
|
|
|
unsigned OpNum,
|
|
|
|
const SmallVectorImpl<MachineOperand> &MOs,
|
|
|
|
unsigned Size, unsigned Alignment) const;
|
2010-10-19 18:58:51 +00:00
|
|
|
|
2014-03-09 07:44:38 +00:00
|
|
|
bool isHighLatencyDef(int opc) const override;
|
2011-03-05 08:00:22 +00:00
|
|
|
|
2010-10-19 18:58:51 +00:00
|
|
|
bool hasHighOperandLatency(const InstrItineraryData *ItinData,
|
|
|
|
const MachineRegisterInfo *MRI,
|
|
|
|
const MachineInstr *DefMI, unsigned DefIdx,
|
2014-03-09 07:44:38 +00:00
|
|
|
const MachineInstr *UseMI,
|
|
|
|
unsigned UseIdx) const override;
|
2011-03-05 06:31:54 +00:00
|
|
|
|
2012-07-06 17:36:20 +00:00
|
|
|
/// analyzeCompare - For a comparison instruction, return the source registers
|
|
|
|
/// in SrcReg and SrcReg2 if having two register operands, and the value it
|
|
|
|
/// compares against in CmpValue. Return true if the comparison instruction
|
|
|
|
/// can be analyzed.
|
2014-03-09 07:44:38 +00:00
|
|
|
bool analyzeCompare(const MachineInstr *MI, unsigned &SrcReg,
|
|
|
|
unsigned &SrcReg2, int &CmpMask,
|
|
|
|
int &CmpValue) const override;
|
2012-07-06 17:36:20 +00:00
|
|
|
|
|
|
|
/// optimizeCompareInstr - Check if there exists an earlier instruction that
|
|
|
|
/// operates on the same source operands and sets flags in the same way as
|
|
|
|
/// Compare; remove Compare if possible.
|
2014-03-09 07:44:38 +00:00
|
|
|
bool optimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg,
|
|
|
|
unsigned SrcReg2, int CmpMask, int CmpValue,
|
|
|
|
const MachineRegisterInfo *MRI) const override;
|
2012-07-06 17:36:20 +00:00
|
|
|
|
2012-08-02 00:56:42 +00:00
|
|
|
/// optimizeLoadInstr - Try to remove the load by folding it to a register
|
|
|
|
/// operand at the use. We fold the load instructions if and only if the
|
2012-08-02 19:37:32 +00:00
|
|
|
/// def and use are in the same BB. We only look at one load and see
|
|
|
|
/// whether it can be folded into MI. FoldAsLoadDefReg is the virtual register
|
|
|
|
/// defined by the load we are trying to fold. DefMI returns the machine
|
|
|
|
/// instruction that defines FoldAsLoadDefReg, and the function returns
|
|
|
|
/// the machine instruction generated due to folding.
|
2014-03-09 07:44:38 +00:00
|
|
|
MachineInstr* optimizeLoadInstr(MachineInstr *MI,
|
|
|
|
const MachineRegisterInfo *MRI,
|
|
|
|
unsigned &FoldAsLoadDefReg,
|
|
|
|
MachineInstr *&DefMI) const override;
|
2012-08-02 00:56:42 +00:00
|
|
|
|
2008-01-07 01:35:02 +00:00
|
|
|
private:
|
2009-12-11 06:01:48 +00:00
|
|
|
MachineInstr * convertToThreeAddressWithLEA(unsigned MIOpc,
|
|
|
|
MachineFunction::iterator &MFI,
|
|
|
|
MachineBasicBlock::iterator &MBBI,
|
|
|
|
LiveVariables *LV) const;
|
|
|
|
|
2009-11-12 20:55:29 +00:00
|
|
|
/// isFrameOperand - Return true and the FrameIndex if the specified
|
|
|
|
/// operand and follow operands form a reference to the stack frame.
|
|
|
|
bool isFrameOperand(const MachineInstr *MI, unsigned int Op,
|
|
|
|
int &FrameIndex) const;
|
2002-10-25 22:55:53 +00:00
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2002-10-25 22:55:53 +00:00
|
|
|
#endif
|