Skip to content

Commit cbce2a1

Browse files
committed
Calculate MemoryEffect
1 parent 4f219ea commit cbce2a1

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ class IRBuilderBase {
380380
void setConstrainedFPCallAttr(CallBase *I) {
381381
I->addFnAttr(Attribute::StrictFP);
382382
MemoryEffects ME = MemoryEffects::inaccessibleMemOnly();
383+
if (I->getAttributes().hasFnAttr(Attribute::Memory))
384+
ME |= I->getAttributes().getMemoryEffects();
383385
auto A = Attribute::getWithMemoryEffects(getContext(), ME);
384386
I->addFnAttr(A);
385387
}

llvm/include/llvm/IR/InstrTypes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,8 @@ class CallBase : public Instruction {
11581158
/// number of extra operands.
11591159
unsigned getNumSubclassExtraOperandsDynamic() const;
11601160

1161+
MemoryEffects getMemoryEffectsForBundles() const;
1162+
11611163
public:
11621164
using Instruction::getContext;
11631165

llvm/lib/IR/Instructions.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -644,17 +644,23 @@ bool CallBase::hasFloatingPointBundles() const {
644644
getOperandBundle(LLVMContext::OB_fpe_except);
645645
}
646646

647+
MemoryEffects CallBase::getMemoryEffectsForBundles() const {
648+
MemoryEffects ME = MemoryEffects::none();
649+
if (hasFloatingPointBundles())
650+
ME |= MemoryEffects::inaccessibleMemOnly();
651+
if (hasReadingOperandBundles())
652+
ME |= MemoryEffects::readOnly();
653+
if (hasClobberingOperandBundles())
654+
ME |= MemoryEffects::writeOnly();
655+
return ME;
656+
}
657+
647658
MemoryEffects CallBase::getMemoryEffects() const {
648659
MemoryEffects ME = getAttributes().getMemoryEffects();
649660
if (auto *Fn = dyn_cast<Function>(getCalledOperand())) {
650661
MemoryEffects FnME = Fn->getMemoryEffects();
651-
if (hasOperandBundles()) {
652-
// TODO: Add a method to get memory effects for operand bundles instead.
653-
if (hasReadingOperandBundles())
654-
FnME |= MemoryEffects::readOnly();
655-
if (hasClobberingOperandBundles())
656-
FnME |= MemoryEffects::writeOnly();
657-
}
662+
if (hasOperandBundles())
663+
FnME |= getMemoryEffectsForBundles();
658664
ME &= FnME;
659665
}
660666
return ME;

0 commit comments

Comments
 (0)