#include "SILoadStoreOptimizer.h"
#include "AMDGPU.h"
#include "GCNSubtarget.h"
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/InitializePasses.h"
usingnamespacellvm;
#define DEBUG_TYPE …
namespace {
enum InstClassEnum { … };
struct AddressRegs { … };
const unsigned MaxAddressRegs = …;
class SILoadStoreOptimizer { … };
class SILoadStoreOptimizerLegacy : public MachineFunctionPass { … };
static unsigned getOpcodeWidth(const MachineInstr &MI, const SIInstrInfo &TII) { … }
static InstClassEnum getInstClass(unsigned Opc, const SIInstrInfo &TII) { … }
static unsigned getInstSubclass(unsigned Opc, const SIInstrInfo &TII) { … }
InstClassEnum
SILoadStoreOptimizer::getCommonInstClass(const CombineInfo &CI,
const CombineInfo &Paired) { … }
static AddressRegs getRegs(unsigned Opc, const SIInstrInfo &TII) { … }
void SILoadStoreOptimizer::CombineInfo::setMI(MachineBasicBlock::iterator MI,
const SILoadStoreOptimizer &LSO) { … }
}
INITIALIZE_PASS_BEGIN(SILoadStoreOptimizerLegacy, DEBUG_TYPE,
"SI Load Store Optimizer", false, false)
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
INITIALIZE_PASS_END(SILoadStoreOptimizerLegacy, DEBUG_TYPE,
"SI Load Store Optimizer", false, false)
char SILoadStoreOptimizerLegacy::ID = …;
char &llvm::SILoadStoreOptimizerLegacyID = …;
FunctionPass *llvm::createSILoadStoreOptimizerLegacyPass() { … }
static void addDefsUsesToList(const MachineInstr &MI,
DenseSet<Register> &RegDefs,
DenseSet<Register> &RegUses) { … }
bool SILoadStoreOptimizer::canSwapInstructions(
const DenseSet<Register> &ARegDefs, const DenseSet<Register> &ARegUses,
const MachineInstr &A, const MachineInstr &B) const { … }
MachineMemOperand *
SILoadStoreOptimizer::combineKnownAdjacentMMOs(const CombineInfo &CI,
const CombineInfo &Paired) { … }
bool SILoadStoreOptimizer::dmasksCanBeCombined(const CombineInfo &CI,
const SIInstrInfo &TII,
const CombineInfo &Paired) { … }
static unsigned getBufferFormatWithCompCount(unsigned OldFormat,
unsigned ComponentCount,
const GCNSubtarget &STI) { … }
static uint32_t mostAlignedValueInRange(uint32_t Lo, uint32_t Hi) { … }
bool SILoadStoreOptimizer::offsetsCanBeCombined(CombineInfo &CI,
const GCNSubtarget &STI,
CombineInfo &Paired,
bool Modify) { … }
bool SILoadStoreOptimizer::widthsFit(const GCNSubtarget &STM,
const CombineInfo &CI,
const CombineInfo &Paired) { … }
const TargetRegisterClass *
SILoadStoreOptimizer::getDataRegClass(const MachineInstr &MI) const { … }
SILoadStoreOptimizer::CombineInfo *
SILoadStoreOptimizer::checkAndPrepareMerge(CombineInfo &CI,
CombineInfo &Paired) { … }
void SILoadStoreOptimizer::copyToDestRegs(
CombineInfo &CI, CombineInfo &Paired,
MachineBasicBlock::iterator InsertBefore, int OpName,
Register DestReg) const { … }
Register
SILoadStoreOptimizer::copyFromSrcRegs(CombineInfo &CI, CombineInfo &Paired,
MachineBasicBlock::iterator InsertBefore,
int OpName) const { … }
unsigned SILoadStoreOptimizer::read2Opcode(unsigned EltSize) const { … }
unsigned SILoadStoreOptimizer::read2ST64Opcode(unsigned EltSize) const { … }
MachineBasicBlock::iterator
SILoadStoreOptimizer::mergeRead2Pair(CombineInfo &CI, CombineInfo &Paired,
MachineBasicBlock::iterator InsertBefore) { … }
unsigned SILoadStoreOptimizer::write2Opcode(unsigned EltSize) const { … }
unsigned SILoadStoreOptimizer::write2ST64Opcode(unsigned EltSize) const { … }
MachineBasicBlock::iterator SILoadStoreOptimizer::mergeWrite2Pair(
CombineInfo &CI, CombineInfo &Paired,
MachineBasicBlock::iterator InsertBefore) { … }
MachineBasicBlock::iterator
SILoadStoreOptimizer::mergeImagePair(CombineInfo &CI, CombineInfo &Paired,
MachineBasicBlock::iterator InsertBefore) { … }
MachineBasicBlock::iterator SILoadStoreOptimizer::mergeSMemLoadImmPair(
CombineInfo &CI, CombineInfo &Paired,
MachineBasicBlock::iterator InsertBefore) { … }
MachineBasicBlock::iterator SILoadStoreOptimizer::mergeBufferLoadPair(
CombineInfo &CI, CombineInfo &Paired,
MachineBasicBlock::iterator InsertBefore) { … }
MachineBasicBlock::iterator SILoadStoreOptimizer::mergeTBufferLoadPair(
CombineInfo &CI, CombineInfo &Paired,
MachineBasicBlock::iterator InsertBefore) { … }
MachineBasicBlock::iterator SILoadStoreOptimizer::mergeTBufferStorePair(
CombineInfo &CI, CombineInfo &Paired,
MachineBasicBlock::iterator InsertBefore) { … }
MachineBasicBlock::iterator SILoadStoreOptimizer::mergeFlatLoadPair(
CombineInfo &CI, CombineInfo &Paired,
MachineBasicBlock::iterator InsertBefore) { … }
MachineBasicBlock::iterator SILoadStoreOptimizer::mergeFlatStorePair(
CombineInfo &CI, CombineInfo &Paired,
MachineBasicBlock::iterator InsertBefore) { … }
static bool needsConstrainedOpcode(const GCNSubtarget &STM,
ArrayRef<MachineMemOperand *> MMOs,
unsigned Width) { … }
unsigned SILoadStoreOptimizer::getNewOpcode(const CombineInfo &CI,
const CombineInfo &Paired) { … }
std::pair<unsigned, unsigned>
SILoadStoreOptimizer::getSubRegIdxs(const CombineInfo &CI,
const CombineInfo &Paired) { … }
const TargetRegisterClass *
SILoadStoreOptimizer::getTargetRegisterClass(const CombineInfo &CI,
const CombineInfo &Paired) const { … }
MachineBasicBlock::iterator SILoadStoreOptimizer::mergeBufferStorePair(
CombineInfo &CI, CombineInfo &Paired,
MachineBasicBlock::iterator InsertBefore) { … }
MachineOperand
SILoadStoreOptimizer::createRegOrImm(int32_t Val, MachineInstr &MI) const { … }
Register SILoadStoreOptimizer::computeBase(MachineInstr &MI,
const MemAddress &Addr) const { … }
void SILoadStoreOptimizer::updateBaseAndOffset(MachineInstr &MI,
Register NewBase,
int32_t NewOffset) const { … }
std::optional<int32_t>
SILoadStoreOptimizer::extractConstOffset(const MachineOperand &Op) const { … }
void SILoadStoreOptimizer::processBaseWithConstOffset(const MachineOperand &Base,
MemAddress &Addr) const { … }
bool SILoadStoreOptimizer::promoteConstantOffsetToImm(
MachineInstr &MI,
MemInfoMap &Visited,
SmallPtrSet<MachineInstr *, 4> &AnchorList) const { … }
void SILoadStoreOptimizer::addInstToMergeableList(const CombineInfo &CI,
std::list<std::list<CombineInfo> > &MergeableInsts) const { … }
std::pair<MachineBasicBlock::iterator, bool>
SILoadStoreOptimizer::collectMergeableInsts(
MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End,
MemInfoMap &Visited, SmallPtrSet<MachineInstr *, 4> &AnchorList,
std::list<std::list<CombineInfo>> &MergeableInsts) const { … }
bool SILoadStoreOptimizer::optimizeBlock(
std::list<std::list<CombineInfo> > &MergeableInsts) { … }
bool
SILoadStoreOptimizer::optimizeInstsWithSameBaseAddr(
std::list<CombineInfo> &MergeList,
bool &OptimizeListAgain) { … }
bool SILoadStoreOptimizerLegacy::runOnMachineFunction(MachineFunction &MF) { … }
bool SILoadStoreOptimizer::run(MachineFunction &MF) { … }
PreservedAnalyses
SILoadStoreOptimizerPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) { … }