#include "SIFoldOperands.h"
#include "AMDGPU.h"
#include "GCNSubtarget.h"
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
#include "SIMachineFunctionInfo.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineOperand.h"
#define DEBUG_TYPE …
usingnamespacellvm;
namespace {
struct FoldCandidate { … };
class SIFoldOperandsImpl { … };
class SIFoldOperandsLegacy : public MachineFunctionPass { … };
}
INITIALIZE_PASS(…)
char SIFoldOperandsLegacy::ID = …;
char &llvm::SIFoldOperandsLegacyID = …;
static const TargetRegisterClass *getRegOpRC(const MachineRegisterInfo &MRI,
const TargetRegisterInfo &TRI,
const MachineOperand &MO) { … }
static unsigned macToMad(unsigned Opc) { … }
bool SIFoldOperandsImpl::frameIndexMayFold(
const MachineInstr &UseMI, int OpNo, const MachineOperand &OpToFold) const { … }
FunctionPass *llvm::createSIFoldOperandsLegacyPass() { … }
bool SIFoldOperandsImpl::canUseImmWithOpSel(FoldCandidate &Fold) const { … }
bool SIFoldOperandsImpl::tryFoldImmWithOpSel(FoldCandidate &Fold) const { … }
bool SIFoldOperandsImpl::updateOperand(FoldCandidate &Fold) const { … }
static bool isUseMIInFoldList(ArrayRef<FoldCandidate> FoldList,
const MachineInstr *MI) { … }
static void appendFoldCandidate(SmallVectorImpl<FoldCandidate> &FoldList,
MachineInstr *MI, unsigned OpNo,
MachineOperand *FoldOp, bool Commuted = false,
int ShrinkOp = -1) { … }
bool SIFoldOperandsImpl::tryAddToFoldList(
SmallVectorImpl<FoldCandidate> &FoldList, MachineInstr *MI, unsigned OpNo,
MachineOperand *OpToFold) const { … }
bool SIFoldOperandsImpl::isUseSafeToFold(const MachineInstr &MI,
const MachineOperand &UseMO) const { … }
bool SIFoldOperandsImpl::getRegSeqInit(
SmallVectorImpl<std::pair<MachineOperand *, unsigned>> &Defs,
Register UseReg, uint8_t OpTy) const { … }
bool SIFoldOperandsImpl::tryToFoldACImm(
const MachineOperand &OpToFold, MachineInstr *UseMI, unsigned UseOpIdx,
SmallVectorImpl<FoldCandidate> &FoldList) const { … }
void SIFoldOperandsImpl::foldOperand(
MachineOperand &OpToFold, MachineInstr *UseMI, int UseOpIdx,
SmallVectorImpl<FoldCandidate> &FoldList,
SmallVectorImpl<MachineInstr *> &CopiesToReplace) const { … }
static bool evalBinaryInstruction(unsigned Opcode, int32_t &Result,
uint32_t LHS, uint32_t RHS) { … }
static unsigned getMovOpc(bool IsScalar) { … }
static void mutateCopyOp(MachineInstr &MI, const MCInstrDesc &NewDesc) { … }
MachineOperand *
SIFoldOperandsImpl::getImmOrMaterializedImm(MachineOperand &Op) const { … }
bool SIFoldOperandsImpl::tryConstantFoldOp(MachineInstr *MI) const { … }
bool SIFoldOperandsImpl::tryFoldCndMask(MachineInstr &MI) const { … }
bool SIFoldOperandsImpl::tryFoldZeroHighBits(MachineInstr &MI) const { … }
bool SIFoldOperandsImpl::foldInstOperand(MachineInstr &MI,
MachineOperand &OpToFold) const { … }
bool SIFoldOperandsImpl::tryFoldFoldableCopy(
MachineInstr &MI, MachineOperand *&CurrentKnownM0Val) const { … }
const MachineOperand *
SIFoldOperandsImpl::isClamp(const MachineInstr &MI) const { … }
bool SIFoldOperandsImpl::tryFoldClamp(MachineInstr &MI) { … }
static int getOModValue(unsigned Opc, int64_t Val) { … }
std::pair<const MachineOperand *, int>
SIFoldOperandsImpl::isOMod(const MachineInstr &MI) const { … }
bool SIFoldOperandsImpl::tryFoldOMod(MachineInstr &MI) { … }
bool SIFoldOperandsImpl::tryFoldRegSequence(MachineInstr &MI) { … }
static bool isAGPRCopy(const SIRegisterInfo &TRI,
const MachineRegisterInfo &MRI, const MachineInstr &Copy,
Register &OutReg, unsigned &OutSubReg) { … }
bool SIFoldOperandsImpl::tryFoldPhiAGPR(MachineInstr &PHI) { … }
bool SIFoldOperandsImpl::tryFoldLoad(MachineInstr &MI) { … }
bool SIFoldOperandsImpl::tryOptimizeAGPRPhis(MachineBasicBlock &MBB) { … }
bool SIFoldOperandsImpl::run(MachineFunction &MF) { … }
PreservedAnalyses SIFoldOperandsPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &) { … }