2012-02-18 20:03:15 +08:00
|
|
|
//===-- X86InstrInfo.h - X86 Instruction Information ------------*- C++ -*-===//
|
2005-04-22 07:38:14 +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
|
2005-04-22 07:38:14 +08:00
|
|
|
//
|
2003-10-21 23:17:13 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-10-26 06:55:53 +08:00
|
|
|
//
|
2003-01-15 06:00:31 +08:00
|
|
|
// This file contains the X86 implementation of the TargetInstrInfo class.
|
2002-10-26 06:55:53 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_TARGET_X86_X86INSTRINFO_H
|
|
|
|
#define LLVM_LIB_TARGET_X86_X86INSTRINFO_H
|
2002-10-26 06:55:53 +08:00
|
|
|
|
2014-03-19 14:53:25 +08:00
|
|
|
#include "MCTargetDesc/X86BaseInfo.h"
|
2016-08-12 06:07:33 +08:00
|
|
|
#include "X86InstrFMA3Info.h"
|
2002-10-26 06:55:53 +08:00
|
|
|
#include "X86RegisterInfo.h"
|
2018-06-21 05:05:02 +08:00
|
|
|
#include "llvm/CodeGen/ISDOpcodes.h"
|
2017-11-08 09:01:31 +08:00
|
|
|
#include "llvm/CodeGen/TargetInstrInfo.h"
|
2018-06-30 01:11:26 +08:00
|
|
|
#include <vector>
|
2002-10-26 06:55:53 +08:00
|
|
|
|
2011-07-02 01:57:27 +08:00
|
|
|
#define GET_INSTRINFO_HEADER
|
|
|
|
#include "X86GenInstrInfo.inc"
|
|
|
|
|
2003-11-12 06:41:34 +08:00
|
|
|
namespace llvm {
|
2017-07-29 10:55:46 +08:00
|
|
|
class MachineInstrBuilder;
|
|
|
|
class X86RegisterInfo;
|
|
|
|
class X86Subtarget;
|
2003-11-12 06:41:34 +08:00
|
|
|
|
2006-10-21 01:42:20 +08:00
|
|
|
namespace X86 {
|
2018-03-10 13:15:22 +08:00
|
|
|
|
|
|
|
enum AsmComments {
|
|
|
|
// For instr that was compressed from EVEX to VEX.
|
|
|
|
AC_EVEX_2_VEX = MachineInstr::TAsmComments
|
|
|
|
};
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Return a pair of condition code for the given predicate and whether
|
2017-05-11 14:36:37 +08:00
|
|
|
/// the instruction operands should be swaped to match the condition code.
|
|
|
|
std::pair<CondCode, bool> getX86ConditionCode(CmpInst::Predicate Predicate);
|
|
|
|
|
2019-04-06 03:27:49 +08:00
|
|
|
/// Return a setcc opcode based on whether it has a memory operand.
|
|
|
|
unsigned getSETOpc(bool HasMemoryOperand = false);
|
2014-06-24 05:55:36 +08:00
|
|
|
|
[X86] Merge the different CMOV instructions for each condition code into single instructions that store the condition code as an immediate.
Summary:
Reorder the condition code enum to match their encodings. Move it to MC layer so it can be used by the scheduler models.
This avoids needing an isel pattern for each condition code. And it removes
translation switches for converting between CMOV instructions and condition
codes.
Now the printer, encoder and disassembler take care of converting the immediate.
We use InstAliases to handle the assembly matching. But we print using the
asm string in the instruction definition. The instruction itself is marked
IsCodeGenOnly=1 to hide it from the assembly parser.
This does complicate the scheduler models a little since we can't assign the
A and BE instructions to a separate class now.
I plan to make similar changes for SETcc and Jcc.
Reviewers: RKSimon, spatel, lebedev.ri, andreadb, courbet
Reviewed By: RKSimon
Subscribers: gchatelet, hiraditya, kristina, lebedev.ri, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60041
llvm-svn: 357800
2019-04-06 03:27:41 +08:00
|
|
|
/// Return a cmov opcode for the given register size in bytes, and operand type.
|
|
|
|
unsigned getCMovOpcode(unsigned RegBytes, bool HasMemoryOperand = false);
|
2014-06-17 07:58:24 +08:00
|
|
|
|
[X86] Merge the different Jcc instructions for each condition code into single instructions that store the condition code as an operand.
Summary:
This avoids needing an isel pattern for each condition code. And it removes translation switches for converting between Jcc instructions and condition codes.
Now the printer, encoder and disassembler take care of converting the immediate. We use InstAliases to handle the assembly matching. But we print using the asm string in the instruction definition. The instruction itself is marked IsCodeGenOnly=1 to hide it from the assembly parser.
Reviewers: spatel, lebedev.ri, courbet, gchatelet, RKSimon
Reviewed By: RKSimon
Subscribers: MatzeB, qcolombet, eraman, hiraditya, arphaman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60228
llvm-svn: 357802
2019-04-06 03:28:09 +08:00
|
|
|
// Turn jCC instruction into condition code.
|
|
|
|
CondCode getCondFromBranch(const MachineInstr &MI);
|
2018-04-02 05:47:55 +08:00
|
|
|
|
[X86] Merge the different Jcc instructions for each condition code into single instructions that store the condition code as an operand.
Summary:
This avoids needing an isel pattern for each condition code. And it removes translation switches for converting between Jcc instructions and condition codes.
Now the printer, encoder and disassembler take care of converting the immediate. We use InstAliases to handle the assembly matching. But we print using the asm string in the instruction definition. The instruction itself is marked IsCodeGenOnly=1 to hide it from the assembly parser.
Reviewers: spatel, lebedev.ri, courbet, gchatelet, RKSimon
Reviewed By: RKSimon
Subscribers: MatzeB, qcolombet, eraman, hiraditya, arphaman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60228
llvm-svn: 357802
2019-04-06 03:28:09 +08:00
|
|
|
// Turn setCC instruction into condition code.
|
2019-04-06 03:27:49 +08:00
|
|
|
CondCode getCondFromSETCC(const MachineInstr &MI);
|
2018-04-02 05:47:55 +08:00
|
|
|
|
[X86] Merge the different Jcc instructions for each condition code into single instructions that store the condition code as an operand.
Summary:
This avoids needing an isel pattern for each condition code. And it removes translation switches for converting between Jcc instructions and condition codes.
Now the printer, encoder and disassembler take care of converting the immediate. We use InstAliases to handle the assembly matching. But we print using the asm string in the instruction definition. The instruction itself is marked IsCodeGenOnly=1 to hide it from the assembly parser.
Reviewers: spatel, lebedev.ri, courbet, gchatelet, RKSimon
Reviewed By: RKSimon
Subscribers: MatzeB, qcolombet, eraman, hiraditya, arphaman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60228
llvm-svn: 357802
2019-04-06 03:28:09 +08:00
|
|
|
// Turn CMov instruction into condition code.
|
[X86] Merge the different CMOV instructions for each condition code into single instructions that store the condition code as an immediate.
Summary:
Reorder the condition code enum to match their encodings. Move it to MC layer so it can be used by the scheduler models.
This avoids needing an isel pattern for each condition code. And it removes
translation switches for converting between CMOV instructions and condition
codes.
Now the printer, encoder and disassembler take care of converting the immediate.
We use InstAliases to handle the assembly matching. But we print using the
asm string in the instruction definition. The instruction itself is marked
IsCodeGenOnly=1 to hide it from the assembly parser.
This does complicate the scheduler models a little since we can't assign the
A and BE instructions to a separate class now.
I plan to make similar changes for SETcc and Jcc.
Reviewers: RKSimon, spatel, lebedev.ri, andreadb, courbet
Reviewed By: RKSimon
Subscribers: gchatelet, hiraditya, kristina, lebedev.ri, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60041
llvm-svn: 357800
2019-04-06 03:27:41 +08:00
|
|
|
CondCode getCondFromCMov(const MachineInstr &MI);
|
2012-09-20 11:06:15 +08:00
|
|
|
|
2016-03-24 05:45:37 +08:00
|
|
|
/// GetOppositeBranchCondition - Return the inverse of the specified cond,
|
|
|
|
/// e.g. turning COND_E to COND_NE.
|
|
|
|
CondCode GetOppositeBranchCondition(CondCode CC);
|
2018-02-20 11:58:11 +08:00
|
|
|
|
2018-06-21 05:05:02 +08:00
|
|
|
/// Get the VPCMP immediate for the given condition.
|
|
|
|
unsigned getVPCMPImmForCond(ISD::CondCode CC);
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Get the VPCMP immediate if the opcodes are swapped.
|
2018-02-20 11:58:11 +08:00
|
|
|
unsigned getSwappedVPCMPImm(unsigned Imm);
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Get the VPCOM immediate if the opcodes are swapped.
|
2018-02-20 11:58:13 +08:00
|
|
|
unsigned getSwappedVPCOMImm(unsigned Imm);
|
|
|
|
|
2019-09-17 12:40:58 +08:00
|
|
|
/// Get the VCMP immediate if the opcodes are swapped.
|
|
|
|
unsigned getSwappedVCMPImm(unsigned Imm);
|
|
|
|
|
2017-07-29 10:55:46 +08:00
|
|
|
} // namespace X86
|
2009-07-10 14:06:17 +08:00
|
|
|
|
2009-07-10 14:29:59 +08:00
|
|
|
/// isGlobalStubReference - Return true if the specified TargetFlag operand is
|
2009-07-10 14:06:17 +08:00
|
|
|
/// a reference to a stub for a global, not the global itself.
|
2009-07-10 14:29:59 +08:00
|
|
|
inline static bool isGlobalStubReference(unsigned char TargetFlag) {
|
|
|
|
switch (TargetFlag) {
|
2017-07-29 10:55:46 +08: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.
|
[MinGW] [X86] Add stubs for references to data variables that might end up imported from a dll
Variables declared with the dllimport attribute are accessed via a
stub variable named __imp_<var>. In MinGW configurations, variables that
aren't declared with a dllimport attribute might still end up imported
from another DLL with runtime pseudo relocs.
For x86_64, this avoids the risk that the target is out of range
for a 32 bit PC relative reference, in case the target DLL is loaded
further than 4 GB from the reference. It also avoids having to make the
text section writable at runtime when doing the runtime fixups, which
makes it worthwhile to do for i386 as well.
Add stub variables for all dso local data references where a definition
of the variable isn't visible within the module, since the DLL data
autoimporting might make them imported even though they are marked as
dso local within LLVM.
Don't do this for variables that actually are defined within the same
module, since we then know for sure that it actually is dso local.
Don't do this for references to functions, since there's no need for
runtime pseudo relocations for autoimporting them; if a function from
a different DLL is called without the appropriate dllimport attribute,
the call just gets routed via a thunk instead.
GCC does something similar since 4.9 (when compiling with -mcmodel=medium
or large; from that version, medium is the default code model for x86_64
mingw), but only for x86_64.
Differential Revision: https://reviews.llvm.org/D51288
llvm-svn: 340942
2018-08-30 01:28:34 +08:00
|
|
|
case X86II::MO_COFFSTUB: // COFF .refptr stub.
|
2009-07-10 14:06:17 +08:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2009-07-10 15:33:30 +08: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) {
|
2017-07-29 10:55:46 +08:00
|
|
|
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_TLVP: // ??? Pretty sure..
|
2009-07-10 15:33:30 +08:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2011-03-05 14:31:54 +08:00
|
|
|
|
2008-06-28 19:07:54 +08:00
|
|
|
inline static bool isScale(const MachineOperand &MO) {
|
2017-07-29 10:55:46 +08:00
|
|
|
return MO.isImm() && (MO.getImm() == 1 || MO.getImm() == 2 ||
|
|
|
|
MO.getImm() == 4 || MO.getImm() == 8);
|
2008-06-28 19:07:54 +08:00
|
|
|
}
|
|
|
|
|
2016-06-30 08:01:54 +08:00
|
|
|
inline static bool isLeaMem(const MachineInstr &MI, unsigned Op) {
|
|
|
|
if (MI.getOperand(Op).isFI())
|
|
|
|
return true;
|
|
|
|
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 19:07:54 +08:00
|
|
|
}
|
|
|
|
|
2016-06-30 08:01:54 +08:00
|
|
|
inline static bool isMem(const MachineInstr &MI, unsigned Op) {
|
|
|
|
if (MI.getOperand(Op).isFI())
|
|
|
|
return true;
|
|
|
|
return Op + X86::AddrNumOperands <= MI.getNumOperands() &&
|
|
|
|
MI.getOperand(Op + X86::AddrSegmentReg).isReg() && isLeaMem(MI, Op);
|
2009-04-09 05:14:34 +08:00
|
|
|
}
|
|
|
|
|
2014-03-31 14:53:13 +08:00
|
|
|
class X86InstrInfo final : public X86GenInstrInfo {
|
2014-06-11 06:34:31 +08:00
|
|
|
X86Subtarget &Subtarget;
|
2002-10-26 06:55:53 +08:00
|
|
|
const X86RegisterInfo RI;
|
2011-03-05 14:31:54 +08:00
|
|
|
|
2013-11-19 08:57:56 +08:00
|
|
|
virtual void anchor();
|
|
|
|
|
2015-06-16 02:44:21 +08:00
|
|
|
bool AnalyzeBranchImpl(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
|
|
|
|
MachineBasicBlock *&FBB,
|
|
|
|
SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
SmallVectorImpl<MachineInstr *> &CondBranches,
|
|
|
|
bool AllowModify) const;
|
|
|
|
|
2002-10-26 06:55:53 +08:00
|
|
|
public:
|
2014-06-11 06:34:31 +08:00
|
|
|
explicit X86InstrInfo(X86Subtarget &STI);
|
2002-10-26 06:55:53 +08:00
|
|
|
|
2003-01-15 06:00:31 +08:00
|
|
|
/// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
|
2002-10-26 06:55:53 +08: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 15:58:15 +08:00
|
|
|
const X86RegisterInfo &getRegisterInfo() const { return RI; }
|
2002-10-26 06:55:53 +08:00
|
|
|
|
2017-04-13 22:10:52 +08:00
|
|
|
/// Returns the stack pointer adjustment that happens inside the frame
|
|
|
|
/// setup..destroy sequence (e.g. by pushes, or inside the callee).
|
|
|
|
int64_t getFrameAdjustment(const MachineInstr &I) const {
|
|
|
|
assert(isFrameInstr(I));
|
2017-05-09 21:35:13 +08:00
|
|
|
if (isFrameSetup(I))
|
|
|
|
return I.getOperand(2).getImm();
|
2017-04-13 22:10:52 +08:00
|
|
|
return I.getOperand(1).getImm();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Sets the stack pointer adjustment made inside the frame made up by this
|
|
|
|
/// instruction.
|
|
|
|
void setFrameAdjustment(MachineInstr &I, int64_t V) const {
|
|
|
|
assert(isFrameInstr(I));
|
2017-05-09 21:35:13 +08:00
|
|
|
if (isFrameSetup(I))
|
|
|
|
I.getOperand(2).setImm(V);
|
|
|
|
else
|
|
|
|
I.getOperand(1).setImm(V);
|
2017-04-13 22:10:52 +08:00
|
|
|
}
|
|
|
|
|
2015-02-02 00:56:04 +08:00
|
|
|
/// getSPAdjust - This returns the stack pointer adjustment made by
|
|
|
|
/// this instruction. For x86, we need to handle more complex call
|
|
|
|
/// sequences involving PUSHes.
|
2016-06-30 08:01:54 +08:00
|
|
|
int getSPAdjust(const MachineInstr &MI) const override;
|
2015-02-02 00:56:04 +08:00
|
|
|
|
2010-01-13 08:30:23 +08: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.
|
2017-07-29 10:55:46 +08:00
|
|
|
bool isCoalescableExtInstr(const MachineInstr &MI, unsigned &SrcReg,
|
|
|
|
unsigned &DstReg, unsigned &SubIdx) const override;
|
2010-01-12 08:09:37 +08:00
|
|
|
|
2016-06-30 08:01:54 +08:00
|
|
|
unsigned isLoadFromStackSlot(const MachineInstr &MI,
|
2014-03-09 15:44:38 +08:00
|
|
|
int &FrameIndex) const override;
|
2018-04-25 06:01:50 +08:00
|
|
|
unsigned isLoadFromStackSlot(const MachineInstr &MI,
|
|
|
|
int &FrameIndex,
|
|
|
|
unsigned &MemBytes) const override;
|
2009-11-13 08:29:53 +08:00
|
|
|
/// isLoadFromStackSlotPostFE - Check for post-frame ptr elimination
|
|
|
|
/// stack locations as well. This uses a heuristic so it isn't
|
|
|
|
/// reliable for correctness.
|
2016-06-30 08:01:54 +08:00
|
|
|
unsigned isLoadFromStackSlotPostFE(const MachineInstr &MI,
|
2014-03-09 15:44:38 +08:00
|
|
|
int &FrameIndex) const override;
|
2009-11-13 04:55:29 +08:00
|
|
|
|
2016-06-30 08:01:54 +08:00
|
|
|
unsigned isStoreToStackSlot(const MachineInstr &MI,
|
2014-03-09 15:44:38 +08:00
|
|
|
int &FrameIndex) const override;
|
2018-04-25 06:01:50 +08:00
|
|
|
unsigned isStoreToStackSlot(const MachineInstr &MI,
|
|
|
|
int &FrameIndex,
|
|
|
|
unsigned &MemBytes) const override;
|
2009-11-13 08:29:53 +08:00
|
|
|
/// isStoreToStackSlotPostFE - Check for post-frame ptr elimination
|
|
|
|
/// stack locations as well. This uses a heuristic so it isn't
|
|
|
|
/// reliable for correctness.
|
2016-06-30 08:01:54 +08:00
|
|
|
unsigned isStoreToStackSlotPostFE(const MachineInstr &MI,
|
2014-03-09 15:44:38 +08:00
|
|
|
int &FrameIndex) const override;
|
2008-04-01 04:40:39 +08:00
|
|
|
|
2016-06-30 08:01:54 +08:00
|
|
|
bool isReallyTriviallyReMaterializable(const MachineInstr &MI,
|
2014-03-09 15:44:38 +08:00
|
|
|
AliasAnalysis *AA) const override;
|
2008-04-01 04:40:39 +08:00
|
|
|
void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
|
2009-07-16 17:20:10 +08:00
|
|
|
unsigned DestReg, unsigned SubIdx,
|
2016-06-30 08:01:54 +08:00
|
|
|
const MachineInstr &Orig,
|
2014-03-09 15:44:38 +08:00
|
|
|
const TargetRegisterInfo &TRI) const override;
|
2008-04-01 04:40:39 +08:00
|
|
|
|
2013-06-11 04:43:49 +08: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.
|
2016-06-30 08:01:54 +08:00
|
|
|
bool classifyLEAReg(MachineInstr &MI, const MachineOperand &Src,
|
2019-08-17 04:50:23 +08:00
|
|
|
unsigned LEAOpcode, bool AllowSP, Register &NewSrc,
|
[x86] don't try to convert add with undef operands to LEA
The existing code tries to handle an undef operand while transforming an add to an LEA,
but it's incomplete because we will crash on the i16 test with the debug output shown below.
It's better to just give up instead. Really, GlobalIsel should have folded these before we
could get into trouble.
# Machine code for function add_undef_i16: NoPHIs, TracksLiveness, Legalized, RegBankSelected, Selected
bb.0 (%ir-block.0):
liveins: $edi
%1:gr32 = COPY killed $edi
%0:gr16 = COPY %1.sub_16bit:gr32
%5:gr64_nosp = IMPLICIT_DEF
%5.sub_16bit:gr64_nosp = COPY %0:gr16
%6:gr64_nosp = IMPLICIT_DEF
%6.sub_16bit:gr64_nosp = COPY %2:gr16
%4:gr32 = LEA64_32r killed %5:gr64_nosp, 1, killed %6:gr64_nosp, 0, $noreg
%3:gr16 = COPY killed %4.sub_16bit:gr32
$ax = COPY killed %3:gr16
RET 0, implicit killed $ax
# End machine code for function add_undef_i16.
*** Bad machine code: Reading virtual register without a def ***
- function: add_undef_i16
- basic block: %bb.0 (0x7fe6cd83d940)
- instruction: %6.sub_16bit:gr64_nosp = COPY %2:gr16
- operand 1: %2:gr16
LLVM ERROR: Found 1 machine code errors.
Differential Revision: https://reviews.llvm.org/D54710
llvm-svn: 348722
2018-12-09 22:40:37 +08:00
|
|
|
bool &isKill, MachineOperand &ImplicitOp,
|
2017-07-29 10:55:46 +08:00
|
|
|
LiveVariables *LV) const;
|
2013-06-11 04:43:49 +08:00
|
|
|
|
2005-01-02 10:37:07 +08: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 15:44:38 +08:00
|
|
|
MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
|
2016-06-30 08:01:54 +08:00
|
|
|
MachineInstr &MI,
|
2014-03-09 15:44:38 +08:00
|
|
|
LiveVariables *LV) const override;
|
2005-01-02 10:37:07 +08:00
|
|
|
|
2015-09-29 04:33:22 +08:00
|
|
|
/// Returns true iff the routine could find two commutable operands in the
|
|
|
|
/// given machine instruction.
|
|
|
|
/// The 'SrcOpIdx1' and 'SrcOpIdx2' are INPUT and OUTPUT arguments. Their
|
|
|
|
/// input values can be re-defined in this method only if the input values
|
|
|
|
/// are not pre-defined, which is designated by the special value
|
|
|
|
/// 'CommuteAnyOperandIndex' assigned to it.
|
|
|
|
/// If both of indices are pre-defined and refer to some operands, then the
|
|
|
|
/// method simply returns true if the corresponding operands are commutable
|
|
|
|
/// and returns false otherwise.
|
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.
llvm-svn: 19686
2005-01-19 15:11:01 +08:00
|
|
|
///
|
2015-09-29 04:33:22 +08:00
|
|
|
/// For example, calling this method this way:
|
|
|
|
/// unsigned Op1 = 1, Op2 = CommuteAnyOperandIndex;
|
|
|
|
/// findCommutedOpIndices(MI, Op1, Op2);
|
|
|
|
/// can be interpreted as a query asking to find an operand that would be
|
|
|
|
/// commutable with the operand#1.
|
2019-09-25 22:55:57 +08:00
|
|
|
bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx1,
|
2014-04-03 07:57:49 +08:00
|
|
|
unsigned &SrcOpIdx2) const override;
|
|
|
|
|
2016-08-12 06:07:33 +08:00
|
|
|
/// Returns an adjusted FMA opcode that must be used in FMA instruction that
|
|
|
|
/// performs the same computations as the given \p MI but which has the
|
|
|
|
/// operands \p SrcOpIdx1 and \p SrcOpIdx2 commuted.
|
|
|
|
/// It may return 0 if it is unsafe to commute the operands.
|
|
|
|
/// Note that a machine instruction (instead of its opcode) is passed as the
|
|
|
|
/// first parameter to make it possible to analyze the instruction's uses and
|
|
|
|
/// commute the first operand of FMA even when it seems unsafe when you look
|
|
|
|
/// at the opcode. For example, it is Ok to commute the first operand of
|
|
|
|
/// VFMADD*SD_Int, if ONLY the lowest 64-bit element of the result is used.
|
|
|
|
///
|
|
|
|
/// The returned FMA opcode may differ from the opcode in the given \p MI.
|
|
|
|
/// For example, commuting the operands #1 and #3 in the following FMA
|
|
|
|
/// FMA213 #1, #2, #3
|
|
|
|
/// results into instruction with adjusted opcode:
|
|
|
|
/// FMA231 #3, #2, #1
|
2017-07-29 10:55:46 +08:00
|
|
|
unsigned
|
|
|
|
getFMA3OpcodeToCommuteOperands(const MachineInstr &MI, unsigned SrcOpIdx1,
|
|
|
|
unsigned SrcOpIdx2,
|
|
|
|
const X86InstrFMA3Group &FMA3Group) const;
|
2015-11-07 03:47:25 +08:00
|
|
|
|
2006-10-21 01:42:20 +08:00
|
|
|
// Branch analysis.
|
2016-02-23 10:46:52 +08:00
|
|
|
bool isUnpredicatedTerminator(const MachineInstr &MI) const override;
|
2017-02-16 08:04:05 +08:00
|
|
|
bool isUnconditionalTailCall(const MachineInstr &MI) const override;
|
|
|
|
bool canMakeTailCallConditional(SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
const MachineInstr &TailCall) const override;
|
|
|
|
void replaceBranchWithTailCall(MachineBasicBlock &MBB,
|
|
|
|
SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
const MachineInstr &TailCall) const override;
|
|
|
|
|
2016-07-15 22:41:04 +08:00
|
|
|
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
|
2014-03-09 15:44:38 +08:00
|
|
|
MachineBasicBlock *&FBB,
|
|
|
|
SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
bool AllowModify) const override;
|
2015-06-16 02:44:14 +08:00
|
|
|
|
2019-04-19 17:08:38 +08:00
|
|
|
bool getMemOperandWithOffset(const MachineInstr &LdSt,
|
|
|
|
const MachineOperand *&BaseOp,
|
2018-11-28 20:00:20 +08:00
|
|
|
int64_t &Offset,
|
|
|
|
const TargetRegisterInfo *TRI) const override;
|
2016-07-15 22:41:04 +08:00
|
|
|
bool analyzeBranchPredicate(MachineBasicBlock &MBB,
|
2015-06-16 02:44:21 +08:00
|
|
|
TargetInstrInfo::MachineBranchPredicate &MBP,
|
|
|
|
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;
|
2017-07-29 10:55:46 +08:00
|
|
|
bool canInsertSelect(const MachineBasicBlock &, ArrayRef<MachineOperand> Cond,
|
|
|
|
unsigned, unsigned, int &, int &, int &) const override;
|
2016-06-12 23:39:02 +08:00
|
|
|
void insertSelect(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
|
|
|
|
const DebugLoc &DL, unsigned DstReg,
|
|
|
|
ArrayRef<MachineOperand> Cond, unsigned TrueReg,
|
|
|
|
unsigned FalseReg) const override;
|
|
|
|
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
|
|
|
|
const DebugLoc &DL, unsigned DestReg, unsigned SrcReg,
|
2014-03-09 15:44:38 +08:00
|
|
|
bool KillSrc) const override;
|
|
|
|
void storeRegToStackSlot(MachineBasicBlock &MBB,
|
2017-07-29 10:55:46 +08:00
|
|
|
MachineBasicBlock::iterator MI, unsigned SrcReg,
|
|
|
|
bool isKill, int FrameIndex,
|
2014-03-09 15:44:38 +08:00
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
const TargetRegisterInfo *TRI) const override;
|
2008-01-02 05:11:32 +08:00
|
|
|
|
2014-03-09 15:44:38 +08:00
|
|
|
void loadRegFromStackSlot(MachineBasicBlock &MBB,
|
2017-07-29 10:55:46 +08:00
|
|
|
MachineBasicBlock::iterator MI, unsigned DestReg,
|
|
|
|
int FrameIndex, const TargetRegisterClass *RC,
|
2014-03-09 15:44:38 +08:00
|
|
|
const TargetRegisterInfo *TRI) const override;
|
2008-01-02 05:11:32 +08:00
|
|
|
|
2016-06-30 08:01:54 +08:00
|
|
|
bool expandPostRAPseudo(MachineInstr &MI) const override;
|
2011-09-29 13:10:54 +08:00
|
|
|
|
2016-11-24 02:33:49 +08:00
|
|
|
/// Check whether the target can fold a load that feeds a subreg operand
|
|
|
|
/// (or a subreg operand that feeds a store).
|
|
|
|
bool isSubregFoldable() const override { return true; }
|
|
|
|
|
2008-01-07 09:35:02 +08: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.
|
2016-06-30 08:01:54 +08:00
|
|
|
MachineInstr *
|
|
|
|
foldMemoryOperandImpl(MachineFunction &MF, MachineInstr &MI,
|
|
|
|
ArrayRef<unsigned> Ops,
|
|
|
|
MachineBasicBlock::iterator InsertPt, int FrameIndex,
|
2019-06-08 14:19:15 +08:00
|
|
|
LiveIntervals *LIS = nullptr,
|
|
|
|
VirtRegMap *VRM = nullptr) const override;
|
2008-01-07 09:35:02 +08: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.
|
2016-06-30 08:01:54 +08:00
|
|
|
MachineInstr *foldMemoryOperandImpl(
|
|
|
|
MachineFunction &MF, MachineInstr &MI, ArrayRef<unsigned> Ops,
|
|
|
|
MachineBasicBlock::iterator InsertPt, MachineInstr &LoadMI,
|
|
|
|
LiveIntervals *LIS = nullptr) const override;
|
2008-01-07 09:35:02 +08: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.
|
2016-06-30 08:01:54 +08:00
|
|
|
bool
|
|
|
|
unfoldMemoryOperand(MachineFunction &MF, MachineInstr &MI, unsigned Reg,
|
|
|
|
bool UnfoldLoad, bool UnfoldStore,
|
|
|
|
SmallVectorImpl<MachineInstr *> &NewMIs) const override;
|
2008-01-07 09:35:02 +08:00
|
|
|
|
2014-03-09 15:44:38 +08:00
|
|
|
bool unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
|
2017-07-29 10:55:46 +08:00
|
|
|
SmallVectorImpl<SDNode *> &NewNodes) const override;
|
2008-01-07 09:35:02 +08: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-31 06:18:41 +08: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.
|
2017-07-29 10:55:46 +08:00
|
|
|
unsigned
|
|
|
|
getOpcodeAfterMemoryUnfold(unsigned Opc, bool UnfoldLoad, bool UnfoldStore,
|
|
|
|
unsigned *LoadRegIndex = nullptr) const override;
|
2011-03-05 14:31:54 +08:00
|
|
|
|
2010-01-22 11:34:51 +08: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 15:44:38 +08:00
|
|
|
bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2, int64_t &Offset1,
|
|
|
|
int64_t &Offset2) const override;
|
2010-01-22 11:34:51 +08:00
|
|
|
|
|
|
|
/// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to
|
2017-07-29 10:55:46 +08:00
|
|
|
/// determine (in conjunction with areLoadsFromSameBasePtr) if two loads
|
|
|
|
/// should be scheduled togther. On some targets if two loads are loading from
|
2010-01-22 11:34:51 +08:00
|
|
|
/// 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.
|
2017-07-29 10:55:46 +08:00
|
|
|
bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2, int64_t Offset1,
|
|
|
|
int64_t Offset2,
|
2014-03-09 15:44:38 +08:00
|
|
|
unsigned NumLoads) const override;
|
2010-01-22 11:34:51 +08:00
|
|
|
|
2017-04-22 05:48:41 +08:00
|
|
|
void getNoop(MCInst &NopInst) const override;
|
2010-04-27 07:37:21 +08:00
|
|
|
|
2014-03-09 15:44:38 +08:00
|
|
|
bool
|
2016-09-15 04:43:16 +08:00
|
|
|
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.
llvm-svn: 19686
2005-01-19 15:11:01 +08:00
|
|
|
|
2009-02-07 01:17:30 +08:00
|
|
|
/// isSafeToMoveRegClassDefs - Return true if it's safe to move a machine
|
|
|
|
/// instruction that defines the specified register class.
|
2014-03-09 15:44:38 +08:00
|
|
|
bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const override;
|
2008-10-27 15:14:50 +08:00
|
|
|
|
2014-05-20 16:55:50 +08:00
|
|
|
/// isSafeToClobberEFLAGS - Return true if it's safe insert an instruction tha
|
|
|
|
/// would clobber the EFLAGS condition register. Note the result may be
|
|
|
|
/// conservative. If it cannot definitely determine the safety after visiting
|
|
|
|
/// a few instructions in each direction it assumes it's not safe.
|
|
|
|
bool isSafeToClobberEFLAGS(MachineBasicBlock &MBB,
|
2019-02-15 12:01:39 +08:00
|
|
|
MachineBasicBlock::iterator I) const {
|
|
|
|
return MBB.computeRegisterLiveness(&RI, X86::EFLAGS, I, 4) ==
|
|
|
|
MachineBasicBlock::LQR_Dead;
|
|
|
|
}
|
2014-05-20 16:55:50 +08:00
|
|
|
|
2015-08-27 04:36:52 +08:00
|
|
|
/// True if MI has a condition code def, e.g. EFLAGS, that is
|
|
|
|
/// not marked dead.
|
2016-06-30 08:01:54 +08:00
|
|
|
bool hasLiveCondCodeDef(MachineInstr &MI) const;
|
2015-08-27 04:36:52 +08:00
|
|
|
|
2008-09-30 08:58:23 +08: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-24 02:22:58 +08:00
|
|
|
///
|
2008-09-30 08:58:23 +08:00
|
|
|
unsigned getGlobalBaseReg(MachineFunction *MF) const;
|
2008-09-24 02:22:58 +08:00
|
|
|
|
2011-09-28 06:57:18 +08:00
|
|
|
std::pair<uint16_t, uint16_t>
|
2016-06-30 08:01:54 +08:00
|
|
|
getExecutionDomain(const MachineInstr &MI) const override;
|
2010-03-30 07:24:21 +08:00
|
|
|
|
2018-01-16 06:18:45 +08:00
|
|
|
uint16_t getExecutionDomainCustom(const MachineInstr &MI) const;
|
|
|
|
|
2016-06-30 08:01:54 +08:00
|
|
|
void setExecutionDomain(MachineInstr &MI, unsigned Domain) const override;
|
2010-03-26 01:25:00 +08:00
|
|
|
|
2018-01-16 06:18:45 +08:00
|
|
|
bool setExecutionDomainCustom(MachineInstr &MI, unsigned Domain) const;
|
|
|
|
|
2014-03-09 15:44:38 +08:00
|
|
|
unsigned
|
2016-06-30 08:01:54 +08:00
|
|
|
getPartialRegUpdateClearance(const MachineInstr &MI, unsigned OpNum,
|
|
|
|
const TargetRegisterInfo *TRI) const override;
|
|
|
|
unsigned getUndefRegClearance(const MachineInstr &MI, unsigned &OpNum,
|
2014-03-09 15:44:38 +08:00
|
|
|
const TargetRegisterInfo *TRI) const override;
|
2016-06-30 08:01:54 +08:00
|
|
|
void breakPartialRegDependency(MachineInstr &MI, unsigned OpNum,
|
2014-03-09 15:44:38 +08:00
|
|
|
const TargetRegisterInfo *TRI) const override;
|
2011-11-15 09:15:30 +08:00
|
|
|
|
2016-06-30 08:01:54 +08:00
|
|
|
MachineInstr *foldMemoryOperandImpl(MachineFunction &MF, MachineInstr &MI,
|
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.
llvm-svn: 113102
2010-09-05 10:18:34 +08:00
|
|
|
unsigned OpNum,
|
2015-02-28 20:04:00 +08:00
|
|
|
ArrayRef<MachineOperand> MOs,
|
2015-06-09 04:09:58 +08:00
|
|
|
MachineBasicBlock::iterator InsertPt,
|
2014-10-21 06:14:22 +08:00
|
|
|
unsigned Size, unsigned Alignment,
|
|
|
|
bool AllowCommute) const;
|
2010-10-20 02:58:51 +08:00
|
|
|
|
2014-03-09 15:44:38 +08:00
|
|
|
bool isHighLatencyDef(int opc) const override;
|
2011-03-05 16:00:22 +08:00
|
|
|
|
2015-06-13 11:42:11 +08:00
|
|
|
bool hasHighOperandLatency(const TargetSchedModel &SchedModel,
|
2010-10-20 02:58:51 +08:00
|
|
|
const MachineRegisterInfo *MRI,
|
2016-06-30 08:01:54 +08:00
|
|
|
const MachineInstr &DefMI, unsigned DefIdx,
|
|
|
|
const MachineInstr &UseMI,
|
2014-03-09 15:44:38 +08:00
|
|
|
unsigned UseIdx) const override;
|
2016-06-30 08:01:54 +08:00
|
|
|
|
2017-07-29 10:55:46 +08:00
|
|
|
bool useMachineCombiner() const override { return true; }
|
2015-09-21 23:09:11 +08:00
|
|
|
|
|
|
|
bool isAssociativeAndCommutative(const MachineInstr &Inst) const override;
|
|
|
|
|
|
|
|
bool hasReassociableOperands(const MachineInstr &Inst,
|
|
|
|
const MachineBasicBlock *MBB) const override;
|
|
|
|
|
|
|
|
void setSpecialOperandAttr(MachineInstr &OldMI1, MachineInstr &OldMI2,
|
|
|
|
MachineInstr &NewMI1,
|
|
|
|
MachineInstr &NewMI2) const override;
|
2015-06-11 04:32:21 +08:00
|
|
|
|
2012-07-07 01:36:20 +08: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.
|
2016-06-30 08:01:54 +08:00
|
|
|
bool analyzeCompare(const MachineInstr &MI, unsigned &SrcReg,
|
2014-03-09 15:44:38 +08:00
|
|
|
unsigned &SrcReg2, int &CmpMask,
|
|
|
|
int &CmpValue) const override;
|
2012-07-07 01:36:20 +08: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.
|
2016-06-30 08:01:54 +08:00
|
|
|
bool optimizeCompareInstr(MachineInstr &CmpInstr, unsigned SrcReg,
|
2014-03-09 15:44:38 +08:00
|
|
|
unsigned SrcReg2, int CmpMask, int CmpValue,
|
|
|
|
const MachineRegisterInfo *MRI) const override;
|
2012-07-07 01:36:20 +08:00
|
|
|
|
2012-08-02 08:56:42 +08: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-03 03:37:32 +08: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.
|
2016-06-30 08:01:54 +08:00
|
|
|
MachineInstr *optimizeLoadInstr(MachineInstr &MI,
|
2014-03-09 15:44:38 +08:00
|
|
|
const MachineRegisterInfo *MRI,
|
|
|
|
unsigned &FoldAsLoadDefReg,
|
|
|
|
MachineInstr *&DefMI) const override;
|
2012-08-02 08:56:42 +08:00
|
|
|
|
2015-08-06 08:44:07 +08:00
|
|
|
std::pair<unsigned, unsigned>
|
|
|
|
decomposeMachineOperandsTargetFlags(unsigned TF) const override;
|
|
|
|
|
|
|
|
ArrayRef<std::pair<unsigned, const char *>>
|
|
|
|
getSerializableDirectMachineOperandTargetFlags() const override;
|
|
|
|
|
2018-07-25 04:13:10 +08:00
|
|
|
virtual outliner::OutlinedFunction getOutliningCandidateInfo(
|
2018-06-05 05:14:16 +08:00
|
|
|
std::vector<outliner::Candidate> &RepeatedSequenceLocs) const override;
|
2017-03-07 05:31:18 +08:00
|
|
|
|
[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-03-07 05:31:18 +08:00
|
|
|
|
2018-06-05 05:14:16 +08:00
|
|
|
outliner::InstrType
|
[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;
|
2017-03-07 05:31:18 +08:00
|
|
|
|
2018-06-20 05:14:48 +08:00
|
|
|
void buildOutlinedFrame(MachineBasicBlock &MBB, MachineFunction &MF,
|
2018-07-25 04:13:10 +08:00
|
|
|
const outliner::OutlinedFunction &OF) const override;
|
2017-03-07 05:31:18 +08:00
|
|
|
|
|
|
|
MachineBasicBlock::iterator
|
|
|
|
insertOutlinedCall(Module &M, MachineBasicBlock &MBB,
|
2017-07-29 10:55:46 +08:00
|
|
|
MachineBasicBlock::iterator &It, MachineFunction &MF,
|
2018-07-25 01:42:11 +08:00
|
|
|
const outliner::Candidate &C) const override;
|
2017-07-29 10:55:46 +08:00
|
|
|
|
2018-11-28 04:58:27 +08:00
|
|
|
#define GET_INSTRINFO_HELPER_DECLS
|
[tblgen][PredicateExpander] Add the ability to describe more complex constraints on instruction operands.
Before this patch, class PredicateExpander only knew how to expand simple
predicates that performed checks on instruction operands.
In particular, the new scheduling predicate syntax was not rich enough to
express checks like this one:
Foo(MI->getOperand(0).getImm()) == ExpectedVal;
Here, the immediate operand value at index zero is passed in input to function
Foo, and ExpectedVal is compared against the value returned by function Foo.
While this predicate pattern doesn't show up in any X86 model, it shows up in
other upstream targets. So, being able to support those predicates is
fundamental if we want to be able to modernize all the scheduling models
upstream.
With this patch, we allow users to specify if a register/immediate operand value
needs to be passed in input to a function as part of the predicate check. Now,
register/immediate operand checks all derive from base class CheckOperandBase.
This patch also changes where TIIPredicate definitions are expanded by the
instructon info emitter. Before, definitions were expanded in class
XXXGenInstrInfo (where XXX is a target name).
With the introduction of this new syntax, we may want to have TIIPredicates
expanded directly in XXXInstrInfo. That is because functions used by the new
operand predicates may only exist in the derived class (i.e. XXXInstrInfo).
This patch is a non functional change for the existing scheduling models.
In future, we will be able to use this richer syntax to better describe complex
scheduling predicates, and expose them to llvm-mca.
Differential Revision: https://reviews.llvm.org/D53880
llvm-svn: 345714
2018-10-31 20:28:05 +08:00
|
|
|
#include "X86GenInstrInfo.inc"
|
|
|
|
|
[X86][Btver2] Fix latency and throughput of CMPXCHG instructions.
On Jaguar, CMPXCHG has a latency of 11cy, and a maximum throughput of 0.33 IPC.
Throughput is superiorly limited to 0.33 because of the implicit in/out
dependency on register EAX. In the case of repeated non-atomic CMPXCHG with the
same memory location, store-to-load forwarding occurs and values for sequent
loads are quickly forwarded from the store buffer.
Interestingly, the functionality in LLVM that computes the reciprocal throughput
doesn't seem to know about RMW instructions. That functionality only looks at
the "consumed resource cycles" for the throughput computation. It should be
fixed/improved by a future patch. In particular, for RMW instructions, that
logic should also take into account for the write latency of in/out register
operands.
An atomic CMPXCHG has a latency of ~17cy. Throughput is also limited to
~17cy/inst due to cache locking, which prevents other memory uOPs to start
executing before the "lock releasing" store uOP.
CMPXCHG8rr and CMPXCHG8rm are treated specially because they decode to one less
macro opcode. Their latency tend to be the same as the other RR/RM variants. RR
variants are relatively fast 3cy (but still microcoded - 5 macro opcodes).
CMPXCHG8B is 11cy and unfortunately doesn't seem to benefit from store-to-load
forwarding. That means, throughput is clearly limited by the in/out dependency
on GPR registers. The uOP composition is sadly unknown (due to the lack of PMCs
for the Integer pipes). I have reused the same mix of consumed resource from the
other CMPXCHG instructions for CMPXCHG8B too.
LOCK CMPXCHG8B is instead 18cycles.
CMPXCHG16B is 32cycles. Up to 38cycles when the LOCK prefix is specified. Due to
the in/out dependencies, throughput is limited to 1 instruction every 32 (or 38)
cycles dependeing on whether the LOCK prefix is specified or not.
I wouldn't be surprised if the microcode for CMPXCHG16B is similar to 2x
microcode from CMPXCHG8B. So, I have speculatively set the JALU01 consumption to
2x the resource cycles used for CMPXCHG8B.
The two new hasLockPrefix() functions are used by the btver2 scheduling model
check if a MCInst/MachineInst has a LOCK prefix. Calls to hasLockPrefix() have
been encoded in predicates of variant scheduling classes that describe lat/thr
of CMPXCHG.
Differential Revision: https://reviews.llvm.org/D66424
llvm-svn: 369365
2019-08-20 18:23:55 +08:00
|
|
|
static bool hasLockPrefix(const MachineInstr &MI) {
|
|
|
|
return MI.getDesc().TSFlags & X86II::LOCK;
|
|
|
|
}
|
|
|
|
|
2019-08-01 00:51:28 +08:00
|
|
|
Optional<ParamLoadedValue>
|
|
|
|
describeLoadedValue(const MachineInstr &MI) const override;
|
|
|
|
|
2015-09-29 04:33:22 +08:00
|
|
|
protected:
|
|
|
|
/// Commutes the operands in the given instruction by changing the operands
|
|
|
|
/// order and/or changing the instruction's opcode and/or the immediate value
|
|
|
|
/// operand.
|
|
|
|
///
|
|
|
|
/// The arguments 'CommuteOpIdx1' and 'CommuteOpIdx2' specify the operands
|
|
|
|
/// to be commuted.
|
|
|
|
///
|
|
|
|
/// Do not call this method for a non-commutable instruction or
|
|
|
|
/// non-commutable operands.
|
|
|
|
/// Even though the instruction is commutable, the method may still
|
|
|
|
/// fail to commute the operands, null pointer is returned in such cases.
|
2016-06-30 08:01:54 +08:00
|
|
|
MachineInstr *commuteInstructionImpl(MachineInstr &MI, bool NewMI,
|
2015-09-29 04:33:22 +08:00
|
|
|
unsigned CommuteOpIdx1,
|
|
|
|
unsigned CommuteOpIdx2) const override;
|
|
|
|
|
2018-08-30 22:32:47 +08:00
|
|
|
/// If the specific machine instruction is a instruction that moves/copies
|
|
|
|
/// value from one register to another register return true along with
|
|
|
|
/// @Source machine operand and @Destination machine operand.
|
|
|
|
bool isCopyInstrImpl(const MachineInstr &MI, const MachineOperand *&Source,
|
|
|
|
const MachineOperand *&Destination) const override;
|
|
|
|
|
2008-01-07 09:35:02 +08:00
|
|
|
private:
|
2018-12-13 01:58:27 +08:00
|
|
|
/// This is a helper for convertToThreeAddress for 8 and 16-bit instructions.
|
2018-12-11 23:29:40 +08:00
|
|
|
/// We use 32-bit LEA to form 3-address code by promoting to a 32-bit
|
2018-12-13 01:58:27 +08:00
|
|
|
/// super-register and then truncating back down to a 8/16-bit sub-register.
|
2016-06-30 08:01:54 +08:00
|
|
|
MachineInstr *convertToThreeAddressWithLEA(unsigned MIOpc,
|
|
|
|
MachineFunction::iterator &MFI,
|
|
|
|
MachineInstr &MI,
|
2019-03-06 02:37:33 +08:00
|
|
|
LiveVariables *LV,
|
|
|
|
bool Is8BitOp) const;
|
2009-12-11 14:01:48 +08:00
|
|
|
|
2015-11-05 04:48:09 +08:00
|
|
|
/// Handles memory folding for special case instructions, for instance those
|
|
|
|
/// requiring custom manipulation of the address.
|
2016-06-30 08:01:54 +08:00
|
|
|
MachineInstr *foldMemoryOperandCustom(MachineFunction &MF, MachineInstr &MI,
|
2015-11-05 04:48:09 +08:00
|
|
|
unsigned OpNum,
|
|
|
|
ArrayRef<MachineOperand> MOs,
|
|
|
|
MachineBasicBlock::iterator InsertPt,
|
|
|
|
unsigned Size, unsigned Align) const;
|
|
|
|
|
2009-11-13 04:55:29 +08:00
|
|
|
/// isFrameOperand - Return true and the FrameIndex if the specified
|
|
|
|
/// operand and follow operands form a reference to the stack frame.
|
2016-06-30 08:01:54 +08:00
|
|
|
bool isFrameOperand(const MachineInstr &MI, unsigned int Op,
|
2009-11-13 04:55:29 +08:00
|
|
|
int &FrameIndex) const;
|
2016-09-22 11:00:50 +08:00
|
|
|
|
|
|
|
/// Returns true iff the routine could find two commutable operands in the
|
|
|
|
/// given machine instruction with 3 vector inputs.
|
|
|
|
/// The 'SrcOpIdx1' and 'SrcOpIdx2' are INPUT and OUTPUT arguments. Their
|
|
|
|
/// input values can be re-defined in this method only if the input values
|
|
|
|
/// are not pre-defined, which is designated by the special value
|
|
|
|
/// 'CommuteAnyOperandIndex' assigned to it.
|
|
|
|
/// If both of indices are pre-defined and refer to some operands, then the
|
|
|
|
/// method simply returns true if the corresponding operands are commutable
|
|
|
|
/// and returns false otherwise.
|
|
|
|
///
|
|
|
|
/// For example, calling this method this way:
|
|
|
|
/// unsigned Op1 = 1, Op2 = CommuteAnyOperandIndex;
|
|
|
|
/// findThreeSrcCommutedOpIndices(MI, Op1, Op2);
|
|
|
|
/// can be interpreted as a query asking to find an operand that would be
|
|
|
|
/// commutable with the operand#1.
|
2018-06-25 14:05:37 +08:00
|
|
|
///
|
|
|
|
/// If IsIntrinsic is set, operand 1 will be ignored for commuting.
|
2016-09-22 11:00:50 +08:00
|
|
|
bool findThreeSrcCommutedOpIndices(const MachineInstr &MI,
|
|
|
|
unsigned &SrcOpIdx1,
|
2018-06-25 14:05:37 +08:00
|
|
|
unsigned &SrcOpIdx2,
|
|
|
|
bool IsIntrinsic = false) const;
|
2002-10-26 06:55:53 +08:00
|
|
|
};
|
|
|
|
|
2017-07-29 10:55:46 +08:00
|
|
|
} // namespace llvm
|
2003-11-12 06:41:34 +08:00
|
|
|
|
2002-10-26 06:55:53 +08:00
|
|
|
#endif
|