[GlobalISel] Add convenience constructors to MemDesc

This allows constructing a MemDesc from a MachineMemoryOperand, a pattern that starts to show up more frequently.

Reviewed By: foad

Differential Revision: https://reviews.llvm.org/D109161
This commit is contained in:
Konstantin Schwarz 2021-09-02 16:18:26 +02:00
parent 6ba0b9f68a
commit 90d5298759
3 changed files with 12 additions and 12 deletions

View File

@ -113,6 +113,14 @@ struct LegalityQuery {
LLT MemoryTy;
uint64_t AlignInBits;
AtomicOrdering Ordering;
MemDesc() = default;
MemDesc(LLT MemoryTy, uint64_t AlignInBits, AtomicOrdering Ordering)
: MemoryTy(MemoryTy), AlignInBits(AlignInBits), Ordering(Ordering) {}
MemDesc(const MachineMemOperand &MMO)
: MemoryTy(MMO.getMemoryType()),
AlignInBits(MMO.getAlign().value() * 8),
Ordering(MMO.getSuccessOrdering()) {}
};
/// Operations which require memory can use this to place requirements on the

View File

@ -497,10 +497,7 @@ bool CombinerHelper::matchCombineExtendingLoads(MachineInstr &MI,
continue;
// Check for legality.
if (LI) {
LegalityQuery::MemDesc MMDesc;
MMDesc.MemoryTy = MMO.getMemoryType();
MMDesc.AlignInBits = MMO.getAlign().value() * 8;
MMDesc.Ordering = MMO.getSuccessOrdering();
LegalityQuery::MemDesc MMDesc(MMO);
LLT UseTy = MRI.getType(UseMI.getOperand(0).getReg());
LLT SrcTy = MRI.getType(LoadMI->getPointerReg());
if (LI->getAction({LoadMI->getOpcode(), {UseTy, SrcTy}, {MMDesc}})
@ -724,10 +721,8 @@ bool CombinerHelper::matchSextInRegOfLoad(
return false;
const MachineMemOperand &MMO = LoadDef->getMMO();
LegalityQuery::MemDesc MMDesc;
LegalityQuery::MemDesc MMDesc(MMO);
MMDesc.MemoryTy = LLT::scalar(NewSizeBits);
MMDesc.AlignInBits = MMO.getAlign().value() * 8;
MMDesc.Ordering = MMO.getSuccessOrdering();
if (!isLegalOrBeforeLegalizer({TargetOpcode::G_SEXTLOAD,
{MRI.getType(LoadDef->getDstReg()),
MRI.getType(LoadDef->getPointerReg())},
@ -3758,10 +3753,8 @@ bool CombinerHelper::matchLoadOrCombine(
// may not use index 0.
Register Ptr = LowestIdxLoad->getPointerReg();
const MachineMemOperand &MMO = LowestIdxLoad->getMMO();
LegalityQuery::MemDesc MMDesc;
LegalityQuery::MemDesc MMDesc(MMO);
MMDesc.MemoryTy = Ty;
MMDesc.AlignInBits = MMO.getAlign().value() * 8;
MMDesc.Ordering = MMO.getSuccessOrdering();
if (!isLegalOrBeforeLegalizer(
{TargetOpcode::G_LOAD, {Ty, MRI.getType(Ptr)}, {MMDesc}}))
return false;

View File

@ -352,8 +352,7 @@ LegalizerInfo::getAction(const MachineInstr &MI,
SmallVector<LegalityQuery::MemDesc, 2> MemDescrs;
for (const auto &MMO : MI.memoperands())
MemDescrs.push_back({MMO->getMemoryType(), 8 * MMO->getAlign().value(),
MMO->getSuccessOrdering()});
MemDescrs.push_back({*MMO});
return getAction({MI.getOpcode(), Types, MemDescrs});
}