LLVM  10.0.0svn
Macros | Functions
SIFoldOperands.cpp File Reference
#include "AMDGPU.h"
#include "AMDGPUSubtarget.h"
#include "SIInstrInfo.h"
#include "SIMachineFunctionInfo.h"
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/CodeGen/LiveIntervals.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
Include dependency graph for SIFoldOperands.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "si-fold-operands"
 

Functions

static bool isInlineConstantIfFolded (const SIInstrInfo *TII, const MachineInstr &UseMI, unsigned OpNo, const MachineOperand &OpToFold)
 
static bool frameIndexMayFold (const SIInstrInfo *TII, const MachineInstr &UseMI, int OpNo, const MachineOperand &OpToFold)
 
static bool updateOperand (FoldCandidate &Fold, const SIInstrInfo &TII, const TargetRegisterInfo &TRI, const GCNSubtarget &ST)
 
static bool isUseMIInFoldList (ArrayRef< FoldCandidate > FoldList, const MachineInstr *MI)
 
static bool tryAddToFoldList (SmallVectorImpl< FoldCandidate > &FoldList, MachineInstr *MI, unsigned OpNo, MachineOperand *OpToFold, const SIInstrInfo *TII)
 
static bool isUseSafeToFold (const SIInstrInfo *TII, const MachineInstr &MI, const MachineOperand &UseMO)
 
static bool tryToFoldACImm (const SIInstrInfo *TII, const MachineOperand &OpToFold, MachineInstr *UseMI, unsigned UseOpIdx, SmallVectorImpl< FoldCandidate > &FoldList)
 
static bool evalBinaryInstruction (unsigned Opcode, int32_t &Result, uint32_t LHS, uint32_t RHS)
 
static unsigned getMovOpc (bool IsScalar)
 
static void stripExtraCopyOperands (MachineInstr &MI)
 Remove any leftover implicit operands from mutating the instruction. More...
 
static void mutateCopyOp (MachineInstr &MI, const MCInstrDesc &NewDesc)
 
static MachineOperandgetImmOrMaterializedImm (MachineRegisterInfo &MRI, MachineOperand &Op)
 
static bool tryConstantFoldOp (MachineRegisterInfo &MRI, const SIInstrInfo *TII, MachineInstr *MI, MachineOperand *ImmOp)
 
static bool tryFoldInst (const SIInstrInfo *TII, MachineInstr *MI)
 
static bool hasOneNonDBGUseInst (const MachineRegisterInfo &MRI, unsigned Reg)
 
static int getOModValue (unsigned Opc, int64_t Val)
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "si-fold-operands"

Definition at line 25 of file SIFoldOperands.cpp.

Function Documentation

◆ evalBinaryInstruction()

static bool evalBinaryInstruction ( unsigned  Opcode,
int32_t &  Result,
uint32_t  LHS,
uint32_t  RHS 
)
static

Definition at line 737 of file SIFoldOperands.cpp.

Referenced by tryConstantFoldOp().

◆ frameIndexMayFold()

static bool frameIndexMayFold ( const SIInstrInfo TII,
const MachineInstr UseMI,
int  OpNo,
const MachineOperand OpToFold 
)
static

◆ getImmOrMaterializedImm()

static MachineOperand* getImmOrMaterializedImm ( MachineRegisterInfo MRI,
MachineOperand Op 
)
static

◆ getMovOpc()

static unsigned getMovOpc ( bool  IsScalar)
static

Definition at line 788 of file SIFoldOperands.cpp.

Referenced by tryConstantFoldOp(), and tryFoldInst().

◆ getOModValue()

static int getOModValue ( unsigned  Opc,
int64_t  Val 
)
static

◆ hasOneNonDBGUseInst()

static bool hasOneNonDBGUseInst ( const MachineRegisterInfo MRI,
unsigned  Reg 
)
static

◆ isInlineConstantIfFolded()

static bool isInlineConstantIfFolded ( const SIInstrInfo TII,
const MachineInstr UseMI,
unsigned  OpNo,
const MachineOperand OpToFold 
)
static

◆ isUseMIInFoldList()

static bool isUseMIInFoldList ( ArrayRef< FoldCandidate >  FoldList,
const MachineInstr MI 
)
static

Definition at line 300 of file SIFoldOperands.cpp.

Referenced by tryAddToFoldList().

◆ isUseSafeToFold()

static bool isUseSafeToFold ( const SIInstrInfo TII,
const MachineInstr MI,
const MachineOperand UseMO 
)
static

Definition at line 416 of file SIFoldOperands.cpp.

References llvm::SIInstrInfo::isSDWA(), and llvm::MachineOperand::isUndef().

Referenced by tryToFoldACImm().

◆ mutateCopyOp()

static void mutateCopyOp ( MachineInstr MI,
const MCInstrDesc NewDesc 
)
static

Definition at line 805 of file SIFoldOperands.cpp.

References llvm::MachineInstr::setDesc(), and stripExtraCopyOperands().

Referenced by tryConstantFoldOp(), and tryFoldInst().

◆ stripExtraCopyOperands()

static void stripExtraCopyOperands ( MachineInstr MI)
static

Remove any leftover implicit operands from mutating the instruction.

e.g. if we replace an s_and_b32 with a copy, we don't need the implicit scc def anymore.

Definition at line 795 of file SIFoldOperands.cpp.

References llvm::MachineInstr::getDesc(), llvm::MCInstrDesc::getNumImplicitDefs(), llvm::MCInstrDesc::getNumImplicitUses(), llvm::MCInstrDesc::getNumOperands(), llvm::MachineInstr::getNumOperands(), I, and llvm::MachineInstr::RemoveOperand().

Referenced by mutateCopyOp(), and tryConstantFoldOp().

◆ tryAddToFoldList()

static bool tryAddToFoldList ( SmallVectorImpl< FoldCandidate > &  FoldList,
MachineInstr MI,
unsigned  OpNo,
MachineOperand OpToFold,
const SIInstrInfo TII 
)
static

◆ tryConstantFoldOp()

static bool tryConstantFoldOp ( MachineRegisterInfo MRI,
const SIInstrInfo TII,
MachineInstr MI,
MachineOperand ImmOp 
)
static

◆ tryFoldInst()

static bool tryFoldInst ( const SIInstrInfo TII,
MachineInstr MI 
)
static

◆ tryToFoldACImm()

static bool tryToFoldACImm ( const SIInstrInfo TII,
const MachineOperand OpToFold,
MachineInstr UseMI,
unsigned  UseOpIdx,
SmallVectorImpl< FoldCandidate > &  FoldList 
)
static

Definition at line 423 of file SIFoldOperands.cpp.

References assert(), llvm::MachineOperand::ChangeToFrameIndex(), llvm::MachineOperand::ChangeToImmediate(), llvm::MachineOperand::CreateImm(), llvm::tgtok::Def, E, llvm::SmallVectorTemplateCommon< T >::end(), llvm::execMayBeModifiedBeforeUse(), F(), R600_InstFlag::FC, llvm::find_if(), frameIndexMayFold(), llvm::MachineInstr::getDesc(), llvm::TargetRegisterClass::getID(), llvm::MachineOperand::getImm(), llvm::MachineOperand::getIndex(), llvm::APInt::getLoBits(), llvm::AMDGPU::getNamedOperandIdx(), llvm::MachineInstr::getNumExplicitOperands(), llvm::MCInstrDesc::getNumOperands(), llvm::MachineInstr::getOpcode(), llvm::MachineInstr::getOperand(), llvm::Use::getOperandNo(), llvm::MachineInstr::getOperandNo(), llvm::MachineBasicBlock::getParent(), llvm::MachineOperand::getParent(), llvm::MachineInstr::getParent(), llvm::MachineOperand::getReg(), llvm::AMDGPU::getRegBitWidth(), llvm::MachineFunction::getRegInfo(), llvm::MachineOperand::getSubReg(), llvm::MachineRegisterInfo::getUniqueVRegDef(), I, llvm::MachineInstr::isCopy(), llvm::MachineOperand::isFI(), llvm::SIInstrInfo::isFoldableCopy(), llvm::MachineOperand::isGlobal(), llvm::MachineOperand::isImm(), llvm::MachineOperand::isImplicit(), llvm::SIInstrInfo::isInlineConstant(), llvm::MachineInstr::isMoveImmediate(), llvm::MachineOperand::isReg(), llvm::MachineInstr::isRegSequence(), llvm::MachineOperand::isTied(), isUseSafeToFold(), llvm::MCInstrDesc::isVariadic(), llvm::Register::isVirtualRegister(), MRI, llvm::AMDGPU::OPERAND_REG_INLINE_AC_FIRST, llvm::AMDGPU::OPERAND_REG_INLINE_AC_LAST, llvm::AMDGPU::OPERAND_REG_INLINE_C_INT32, llvm::MCOperandInfo::OperandType, llvm::MCInstrDesc::OpInfo, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorTemplateBase< T >::push_back(), llvm::MCOperandInfo::RegClass, llvm::MachineInstr::RemoveOperand(), llvm::MachineInstr::setDesc(), llvm::MachineOperand::setIsKill(), llvm::MachineOperand::setReg(), llvm::MachineOperand::setSubReg(), Size, TII, TRI, tryAddToFoldList(), UseMI, and UseReg().

◆ updateOperand()

static bool updateOperand ( FoldCandidate &  Fold,
const SIInstrInfo TII,
const TargetRegisterInfo TRI,
const GCNSubtarget ST 
)
static

Definition at line 180 of file SIFoldOperands.cpp.

References assert(), llvm::BuildMI(), llvm::SIInstrInfo::buildShrunkInst(), llvm::MachineOperand::ChangeToFrameIndex(), llvm::MachineOperand::ChangeToGA(), llvm::MachineOperand::ChangeToImmediate(), llvm::MachineBasicBlock::computeRegisterLiveness(), llvm::MachineRegisterInfo::createVirtualRegister(), llvm::MachineInstr::getDebugLoc(), llvm::MachineInstr::getDesc(), llvm::MachineOperand::getImm(), llvm::AMDGPU::getNamedOperandIdx(), llvm::MachineInstr::getNumOperands(), llvm::MachineInstr::getOpcode(), llvm::MachineInstr::getOperand(), llvm::MachineInstr::getOperandNo(), llvm::MachineBasicBlock::getParent(), llvm::MachineInstr::getParent(), llvm::MachineOperand::getReg(), llvm::MachineRegisterInfo::getRegClass(), llvm::MachineFunction::getRegInfo(), llvm::MachineOperand::getSubReg(), llvm::AMDGPUSubtarget::hasInv2PiInlineImm(), I, llvm::MachineOperand::isDef(), llvm::AMDGPU::isInlinableLiteralV216(), llvm::SIInstrFlags::IsMAI, llvm::SIInstrFlags::IsPacked, llvm::MachineOperand::isReg(), llvm::isUInt< 16 >(), llvm::MachineOperand::isUndef(), llvm::RegState::Kill, llvm::MachineBasicBlock::LQR_Dead, MI, llvm::Mod, MRI, llvm::SISrcMods::OP_SEL_0, llvm::SISrcMods::OP_SEL_1, llvm::AMDGPU::OPERAND_REG_IMM_V2FP16, llvm::AMDGPU::OPERAND_REG_IMM_V2INT16, llvm::AMDGPU::OPERAND_REG_INLINE_C_V2FP16, llvm::AMDGPU::OPERAND_REG_INLINE_C_V2INT16, llvm::MachineInstr::RemoveOperand(), llvm::MachineInstr::setDesc(), llvm::MachineOperand::setImm(), llvm::MachineOperand::setIsUndef(), llvm::MachineOperand::setReg(), llvm::MachineOperand::substVirtReg(), TRI, llvm::MCInstrDesc::TSFlags, and llvm::MachineRegisterInfo::use_nodbg_empty().

Referenced by tryFoldInst().