LLVM  10.0.0svn
Public Member Functions | Protected Attributes | List of all members
llvm::CombinerHelper Class Reference

#include "llvm/CodeGen/GlobalISel/CombinerHelper.h"

Collaboration diagram for llvm::CombinerHelper:
Collaboration graph
[legend]

Public Member Functions

 CombinerHelper (GISelChangeObserver &Observer, MachineIRBuilder &B, GISelKnownBits *KB=nullptr, MachineDominatorTree *MDT=nullptr)
 
void replaceRegWith (MachineRegisterInfo &MRI, Register FromReg, Register ToReg) const
 MachineRegisterInfo::replaceRegWith() and inform the observer of the changes. More...
 
void replaceRegOpWith (MachineRegisterInfo &MRI, MachineOperand &FromRegOp, Register ToReg) const
 Replace a single register operand with a new register and inform the observer of the changes. More...
 
bool tryCombineCopy (MachineInstr &MI)
 If MI is COPY, try to combine it. More...
 
bool matchCombineCopy (MachineInstr &MI)
 
void applyCombineCopy (MachineInstr &MI)
 
bool isPredecessor (MachineInstr &DefMI, MachineInstr &UseMI)
 Returns true if DefMI precedes UseMI or they are the same instruction. More...
 
bool dominates (MachineInstr &DefMI, MachineInstr &UseMI)
 Returns true if DefMI dominates UseMI. More...
 
bool tryCombineExtendingLoads (MachineInstr &MI)
 If MI is extend that consumes the result of a load, try to combine it. More...
 
bool matchCombineExtendingLoads (MachineInstr &MI, PreferredTuple &MatchInfo)
 
void applyCombineExtendingLoads (MachineInstr &MI, PreferredTuple &MatchInfo)
 
bool tryCombineIndexedLoadStore (MachineInstr &MI)
 Combine MI into a pre-indexed or post-indexed load/store operation if legal and the surrounding code makes it useful. More...
 
bool matchElideBrByInvertingCond (MachineInstr &MI)
 
void applyElideBrByInvertingCond (MachineInstr &MI)
 
bool tryElideBrByInvertingCond (MachineInstr &MI)
 
bool tryCombineConcatVectors (MachineInstr &MI)
 If MI is G_CONCAT_VECTORS, try to combine it. More...
 
bool matchCombineConcatVectors (MachineInstr &MI, bool &IsUndef, SmallVectorImpl< Register > &Ops)
 Check if the G_CONCAT_VECTORS MI is undef or if it can be flattened into a build_vector. More...
 
void applyCombineConcatVectors (MachineInstr &MI, bool IsUndef, const ArrayRef< Register > Ops)
 Replace MI with a flattened build_vector with Ops or an implicit_def if IsUndef is true. More...
 
bool tryCombineShuffleVector (MachineInstr &MI)
 Try to combine G_SHUFFLE_VECTOR into G_CONCAT_VECTORS. More...
 
bool matchCombineShuffleVector (MachineInstr &MI, SmallVectorImpl< Register > &Ops)
 Check if the G_SHUFFLE_VECTOR MI can be replaced by a concat_vectors. More...
 
void applyCombineShuffleVector (MachineInstr &MI, const ArrayRef< Register > Ops)
 Replace MI with a concat_vectors with Ops. More...
 
bool tryCombineMemCpyFamily (MachineInstr &MI, unsigned MaxLen=0)
 Optimize memcpy intrinsics et al, e.g. More...
 
bool tryCombine (MachineInstr &MI)
 Try to transform MI by using all of the above combine functions. More...
 

Protected Attributes

MachineIRBuilderBuilder
 
MachineRegisterInfoMRI
 
GISelChangeObserverObserver
 
GISelKnownBitsKB
 
MachineDominatorTreeMDT
 

Detailed Description

Definition at line 39 of file CombinerHelper.h.

Constructor & Destructor Documentation

◆ CombinerHelper()

CombinerHelper::CombinerHelper ( GISelChangeObserver Observer,
MachineIRBuilder B,
GISelKnownBits KB = nullptr,
MachineDominatorTree MDT = nullptr 
)

Definition at line 34 of file CombinerHelper.cpp.

Member Function Documentation

◆ applyCombineConcatVectors()

void CombinerHelper::applyCombineConcatVectors ( MachineInstr MI,
bool  IsUndef,
const ArrayRef< Register Ops 
)

◆ applyCombineCopy()

void CombinerHelper::applyCombineCopy ( MachineInstr MI)

◆ applyCombineExtendingLoads()

void CombinerHelper::applyCombineExtendingLoads ( MachineInstr MI,
PreferredTuple MatchInfo 
)

◆ applyCombineShuffleVector()

void CombinerHelper::applyCombineShuffleVector ( MachineInstr MI,
const ArrayRef< Register Ops 
)

◆ applyElideBrByInvertingCond()

void CombinerHelper::applyElideBrByInvertingCond ( MachineInstr MI)

◆ dominates()

bool CombinerHelper::dominates ( MachineInstr DefMI,
MachineInstr UseMI 
)

◆ isPredecessor()

bool CombinerHelper::isPredecessor ( MachineInstr DefMI,
MachineInstr UseMI 
)

Returns true if DefMI precedes UseMI or they are the same instruction.

Both must be in the same basic block.

Definition at line 533 of file CombinerHelper.cpp.

References assert(), llvm::MachineBasicBlock::begin(), llvm::MachineInstr::getParent(), I, llvm_unreachable, and UseMI.

Referenced by dominates().

◆ matchCombineConcatVectors()

bool CombinerHelper::matchCombineConcatVectors ( MachineInstr MI,
bool IsUndef,
SmallVectorImpl< Register > &  Ops 
)

Check if the G_CONCAT_VECTORS MI is undef or if it can be flattened into a build_vector.

In the first case IsUndef will be true. In the second case Ops will contain the operands needed to produce the flattened build_vector.

Precondition
MI.getOpcode() == G_CONCAT_VECTORS.

Definition at line 102 of file CombinerHelper.cpp.

References assert(), Builder, llvm::MachineIRBuilder::buildUndef(), llvm::tgtok::Def, llvm::LLT::getNumElements(), llvm::MachineInstr::getOpcode(), llvm::MachineInstr::getOperand(), llvm::MachineInstr::getParent(), llvm::MachineOperand::getReg(), llvm::LLT::getScalarType(), llvm::MachineRegisterInfo::getType(), llvm::MachineRegisterInfo::getVRegDef(), MI, MRI, llvm::MachineInstr::operands(), llvm::SmallVectorTemplateBase< T >::push_back(), Reg, llvm::MachineIRBuilder::setInsertPt(), and llvm::RegState::Undef.

Referenced by tryCombineConcatVectors().

◆ matchCombineCopy()

bool CombinerHelper::matchCombineCopy ( MachineInstr MI)

◆ matchCombineExtendingLoads()

bool CombinerHelper::matchCombineExtendingLoads ( MachineInstr MI,
PreferredTuple MatchInfo 
)

◆ matchCombineShuffleVector()

bool CombinerHelper::matchCombineShuffleVector ( MachineInstr MI,
SmallVectorImpl< Register > &  Ops 
)

◆ matchElideBrByInvertingCond()

bool CombinerHelper::matchElideBrByInvertingCond ( MachineInstr MI)

◆ replaceRegOpWith()

void CombinerHelper::replaceRegOpWith ( MachineRegisterInfo MRI,
MachineOperand FromRegOp,
Register  ToReg 
) const

Replace a single register operand with a new register and inform the observer of the changes.

Definition at line 54 of file CombinerHelper.cpp.

References assert(), llvm::GISelChangeObserver::changedInstr(), llvm::GISelChangeObserver::changingInstr(), llvm::MachineOperand::getParent(), Observer, and llvm::MachineOperand::setReg().

Referenced by applyCombineExtendingLoads().

◆ replaceRegWith()

void CombinerHelper::replaceRegWith ( MachineRegisterInfo MRI,
Register  FromReg,
Register  ToReg 
) const

◆ tryCombine()

bool CombinerHelper::tryCombine ( MachineInstr MI)

Try to transform MI by using all of the above combine functions.

Returns true if changed.

Definition at line 1298 of file CombinerHelper.cpp.

References tryCombineCopy(), tryCombineExtendingLoads(), and tryCombineIndexedLoadStore().

◆ tryCombineConcatVectors()

bool CombinerHelper::tryCombineConcatVectors ( MachineInstr MI)

If MI is G_CONCAT_VECTORS, try to combine it.

Returns true if MI changed. Right now, we support:

  • concat_vector(undef, undef) => undef
  • concat_vector(build_vector(A, B), build_vector(C, D)) => build_vector(A, B, C, D)
Precondition
MI.getOpcode() == G_CONCAT_VECTORS.

Definition at line 92 of file CombinerHelper.cpp.

References applyCombineConcatVectors(), and matchCombineConcatVectors().

◆ tryCombineCopy()

bool CombinerHelper::tryCombineCopy ( MachineInstr MI)

If MI is COPY, try to combine it.

Returns true if MI changed.

Definition at line 65 of file CombinerHelper.cpp.

References applyCombineCopy(), and matchCombineCopy().

Referenced by tryCombine().

◆ tryCombineExtendingLoads()

bool CombinerHelper::tryCombineExtendingLoads ( MachineInstr MI)

If MI is extend that consumes the result of a load, try to combine it.

Returns true if MI changed.

Definition at line 348 of file CombinerHelper.cpp.

References applyCombineExtendingLoads(), and matchCombineExtendingLoads().

Referenced by tryCombine().

◆ tryCombineIndexedLoadStore()

bool CombinerHelper::tryCombineIndexedLoadStore ( MachineInstr MI)

◆ tryCombineMemCpyFamily()

bool CombinerHelper::tryCombineMemCpyFamily ( MachineInstr MI,
unsigned  MaxLen = 0 
)

Optimize memcpy intrinsics et al, e.g.

constant len calls. /p MaxLen if non-zero specifies the max length of a mem libcall to inline.

For example (pre-indexed):

$addr = G_GEP $base, $offset
[...]
$val = G_LOAD $addr
[...]
$whatever = COPY $addr

–>

$val, $addr = G_INDEXED_LOAD $base, $offset, 1 (IsPre)
[...]
$whatever = COPY $addr

or (post-indexed):

G_STORE $val, $base
[...]
$addr = G_GEP $base, $offset
[...]
$whatever = COPY $addr

–>

$addr = G_INDEXED_STORE $val, $base, $offset
[...]
$whatever = COPY $addr  

Definition at line 1247 of file CombinerHelper.cpp.

References assert(), llvm::MachineInstr::eraseFromParent(), llvm::MachineMemOperand::getBaseAlignment(), llvm::getConstantVRegValWithLookThrough(), llvm::MachineInstr::getIntrinsicID(), llvm::MachineInstr::getOpcode(), llvm::MachineInstr::getOperand(), llvm::MachineOperand::getReg(), llvm::MachineMemOperand::isVolatile(), llvm::MachineInstr::memoperands_begin(), llvm::MachineInstr::memoperands_end(), and MRI.

◆ tryCombineShuffleVector()

bool CombinerHelper::tryCombineShuffleVector ( MachineInstr MI)

Try to combine G_SHUFFLE_VECTOR into G_CONCAT_VECTORS.

Returns true if MI changed.

Precondition
MI.getOpcode() == G_SHUFFLE_VECTOR.

Definition at line 176 of file CombinerHelper.cpp.

References applyCombineShuffleVector(), and matchCombineShuffleVector().

◆ tryElideBrByInvertingCond()

bool CombinerHelper::tryElideBrByInvertingCond ( MachineInstr MI)

Member Data Documentation

◆ Builder

MachineIRBuilder& llvm::CombinerHelper::Builder
protected

◆ KB

GISelKnownBits* llvm::CombinerHelper::KB
protected

Definition at line 44 of file CombinerHelper.h.

◆ MDT

MachineDominatorTree* llvm::CombinerHelper::MDT
protected

Definition at line 45 of file CombinerHelper.h.

Referenced by dominates().

◆ MRI

MachineRegisterInfo& llvm::CombinerHelper::MRI
protected

◆ Observer

GISelChangeObserver& llvm::CombinerHelper::Observer
protected

The documentation for this class was generated from the following files: