26 #define DEBUG_TYPE "si-fold-operands"
42 const char *getPassName()
const override {
43 return "SI Fold Operands";
53 struct FoldCandidate {
60 UseMI(MI), UseOpNo(OpNo) {
62 if (FoldOp->
isImm()) {
64 ImmToFold = FoldOp->
getImm();
66 assert(FoldOp->
isReg());
79 "SI Fold Operands",
false,
false)
84 char SIFoldOperands::
ID = 0;
89 return new SIFoldOperands();
94 case AMDGPU::V_MOV_B32_e32:
95 case AMDGPU::V_MOV_B32_e64:
96 case AMDGPU::V_MOV_B64_PSEUDO:
97 case AMDGPU::S_MOV_B32:
98 case AMDGPU::S_MOV_B64:
131 for (
auto Candidate : FoldList) {
132 if (Candidate.UseMI == MI)
146 if (Opc == AMDGPU::V_MAC_F32_e64 &&
150 MI->
setDesc(TII->get(AMDGPU::V_MAD_F32));
167 unsigned CommuteIdx0;
168 unsigned CommuteIdx1;
172 if (CommuteIdx0 == OpNo)
174 else if (CommuteIdx1 == OpNo)
185 FoldList.push_back(FoldCandidate(MI, OpNo, OpToFold));
200 for (I = MBB.
begin(); I != MBB.
end(); I = Next) {
209 bool FoldingImm = OpToFold.
isImm();
213 if (!FoldingImm && !OpToFold.
isReg())
224 if (OpToFold.
isReg() &&
229 std::vector<FoldCandidate> FoldList;
262 assert(UseOp.
getSubReg() == AMDGPU::sub1);
280 UseMI->
setDesc(TII->get(MovOp));
305 for (FoldCandidate &Fold : FoldList) {
309 assert(Fold.OpToFold && Fold.OpToFold->isReg());
310 Fold.OpToFold->setIsKill(
false);
312 DEBUG(
dbgs() <<
"Folded source from " << MI <<
" into OpNo " <<
313 Fold.UseOpNo <<
" of " << *Fold.UseMI <<
'\n');
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
AMDGPU specific subclass of TargetSubtarget.
const SIRegisterInfo & getRegisterInfo() const override
Describe properties that are true of each instruction in the target description file.
static bool isVirtualRegister(unsigned Reg)
isVirtualRegister - Return true if the specified register number is in the virtual register namespace...
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
unsigned getMovOpcode(const TargetRegisterClass *DstRC) const
MachineInstr * commuteInstruction(MachineInstr *MI, bool NewMI=false) const override
void substVirtReg(unsigned Reg, unsigned SubIdx, const TargetRegisterInfo &)
substVirtReg - Substitute the current register with the virtual subregister Reg:SubReg.
bool isVariadic() const
Return true if this instruction can have a variable number of operands.
COPY - Target-independent register copy.
unsigned getSize() const
getSize - Return the size of the register in bytes, which is also the size of a stack slot allocated ...
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
static use_iterator use_end()
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
A Use represents the edge between a Value definition and its users.
static bool updateOperand(FoldCandidate &Fold, const TargetRegisterInfo &TRI)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
const TargetRegisterClass * getRegClass(unsigned Reg) const
getRegClass - Return the register class of the specified virtual register.
static bool isUseMIInFoldList(const std::vector< FoldCandidate > &FoldList, const MachineInstr *MI)
void untieRegOperand(unsigned OpIdx)
Break any tie involving OpIdx.
bool findCommutedOpIndices(MachineInstr *MI, unsigned &SrcOpIdx1, unsigned &SrcOpIdx2) const override
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
void ChangeToImmediate(int64_t ImmVal)
ChangeToImmediate - Replace this operand with a new immediate operand of the specified value...
bundle_iterator< MachineInstr, instr_iterator > iterator
unsigned getOpSize(uint16_t Opcode, unsigned OpNo) const
Return the size in bytes of the operand OpNo on the given.
unsigned getOperandNo() const
Return the operand # of this use in its User.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
int64_t getSExtValue() const
Get sign extended value.
const MachineOperand & getOperand(unsigned i) const
APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
unsigned getSubReg() const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool isInlineConstant(const APInt &Imm) const
bool isOperandLegal(const MachineInstr *MI, unsigned OpIdx, const MachineOperand *MO=nullptr) const
Check if MO is a legal operand if it was the OpIdx Operand for MI.
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
APInt getHiBits(unsigned numBits) const
Compute an APInt containing numBits highbits from this APInt.
MachineOperand class - Representation of each machine instruction operand.
INITIALIZE_PASS_BEGIN(SIFoldOperands, DEBUG_TYPE,"SI Fold Operands", false, false) INITIALIZE_PASS_END(SIFoldOperands
bool hasOneUse(unsigned RegNo) const
hasOneUse - Return true if there is exactly one instruction using the specified register.
static bool tryAddToFoldList(std::vector< FoldCandidate > &FoldList, MachineInstr *MI, unsigned OpNo, MachineOperand *OpToFold, const SIInstrInfo *TII)
void setPreservesCFG()
This function should be called by the pass, iff they do not:
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Class for arbitrary precision integers.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
const TargetRegisterClass * getPhysRegClass(unsigned Reg) const
Return the 'base' register class for this register.
Representation of each machine instruction.
void initializeSIFoldOperandsPass(PassRegistry &)
Interface definition for SIInstrInfo.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
int16_t RegClass
This specifies the register class enumeration of the operand if the operand is a register.
FunctionPass * createSIFoldOperandsPass()
use_iterator use_begin(unsigned RegNo) const
static unsigned UseReg(const MachineOperand &MO)
static MachineOperand CreateImm(int64_t Val)
unsigned getReg() const
getReg - Returns the register number.
virtual const TargetInstrInfo * getInstrInfo() const
static bool isSafeToFold(unsigned Opcode)
const MCOperandInfo * OpInfo
BasicBlockListType::iterator iterator
int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIndex)
reg_begin/reg_end - Provide iteration support to walk over all definitions and uses of a register wit...
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...