Skip to content

Commit

Permalink
[Alignment][NFC] Simplify IRTranslator::getMemOpAlignment
Browse files Browse the repository at this point in the history
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790

Reviewers: courbet

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77078
  • Loading branch information
gchatelet committed Mar 31, 2020
1 parent 7b808b1 commit af3c52d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
10 changes: 9 additions & 1 deletion llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h
Expand Up @@ -582,7 +582,15 @@ class IRTranslator : public MachineFunctionPass {
/// Get the alignment of the given memory operation instruction. This will
/// either be the explicitly specified value or the ABI-required alignment for
/// the type being accessed (according to the Module's DataLayout).
unsigned getMemOpAlignment(const Instruction &I);
/// FIXME: Remove once transition to Align is over.
inline unsigned getMemOpAlignment(const Instruction &I) {
return getMemOpAlign(I).value();
}

/// Get the alignment of the given memory operation instruction. This will
/// either be the explicitly specified value or the ABI-required alignment for
/// the type being accessed (according to the Module's DataLayout).
Align getMemOpAlign(const Instruction &I);

/// Get the MachineBasicBlock that represents \p BB. Specifically, the block
/// returned will be the head of the translated block (suitable for branch
Expand Down
38 changes: 17 additions & 21 deletions llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
Expand Up @@ -242,37 +242,33 @@ int IRTranslator::getOrCreateFrameIndex(const AllocaInst &AI) {
return FI;
}

unsigned IRTranslator::getMemOpAlignment(const Instruction &I) {
unsigned Alignment = 0;
Type *ValTy = nullptr;
Align IRTranslator::getMemOpAlign(const Instruction &I) {
if (const StoreInst *SI = dyn_cast<StoreInst>(&I)) {
Alignment = SI->getAlignment();
ValTy = SI->getValueOperand()->getType();
} else if (const LoadInst *LI = dyn_cast<LoadInst>(&I)) {
Alignment = LI->getAlignment();
ValTy = LI->getType();
} else if (const AtomicCmpXchgInst *AI = dyn_cast<AtomicCmpXchgInst>(&I)) {
Type *ValTy = SI->getValueOperand()->getType();
return SI->getAlign().getValueOr(DL->getABITypeAlign(ValTy));
}
if (const LoadInst *LI = dyn_cast<LoadInst>(&I)) {
Type *ValTy = LI->getType();
return LI->getAlign().getValueOr(DL->getABITypeAlign(ValTy));
}
if (const AtomicCmpXchgInst *AI = dyn_cast<AtomicCmpXchgInst>(&I)) {
// TODO(PR27168): This instruction has no alignment attribute, but unlike
// the default alignment for load/store, the default here is to assume
// it has NATURAL alignment, not DataLayout-specified alignment.
const DataLayout &DL = AI->getModule()->getDataLayout();
Alignment = DL.getTypeStoreSize(AI->getCompareOperand()->getType());
ValTy = AI->getCompareOperand()->getType();
} else if (const AtomicRMWInst *AI = dyn_cast<AtomicRMWInst>(&I)) {
return Align(DL.getTypeStoreSize(AI->getCompareOperand()->getType()));
}
if (const AtomicRMWInst *AI = dyn_cast<AtomicRMWInst>(&I)) {
// TODO(PR27168): This instruction has no alignment attribute, but unlike
// the default alignment for load/store, the default here is to assume
// it has NATURAL alignment, not DataLayout-specified alignment.
const DataLayout &DL = AI->getModule()->getDataLayout();
Alignment = DL.getTypeStoreSize(AI->getValOperand()->getType());
ValTy = AI->getType();
} else {
OptimizationRemarkMissed R("gisel-irtranslator", "", &I);
R << "unable to translate memop: " << ore::NV("Opcode", &I);
reportTranslationError(*MF, *TPC, *ORE, R);
return 1;
return Align(DL.getTypeStoreSize(AI->getValOperand()->getType()));
}

return Alignment ? Alignment : DL->getABITypeAlignment(ValTy);
OptimizationRemarkMissed R("gisel-irtranslator", "", &I);
R << "unable to translate memop: " << ore::NV("Opcode", &I);
reportTranslationError(*MF, *TPC, *ORE, R);
return Align(1);
}

MachineBasicBlock &IRTranslator::getMBB(const BasicBlock &BB) {
Expand Down

0 comments on commit af3c52d

Please sign in to comment.