Skip to content

Commit

Permalink
[mlir] move alias lattice update to relevant transfer function (#1573)
Browse files Browse the repository at this point in the history
  • Loading branch information
ftynse authored Feb 27, 2024
1 parent 8d75756 commit f7a46fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions enzyme/Enzyme/MLIR/Analysis/AliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,19 @@ void enzyme::PointsToPointerAnalysis::visitOperation(Operation *op,

SmallVector<MemoryEffects::EffectInstance> effects;
memory.getEffects(effects);

// If the operation allocates fresh memory and doesn't write into it, that
// memory is known not to point to any known alias class.
if (effects.size() == 1 &&
isa<MemoryEffects::Allocate>(effects.front().getEffect()) &&
effects.front().getValue()) {
const auto *destClasses =
getOrCreateFor<AliasClassLattice>(op, effects.front().getValue());
propagateIfChanged(
after, after->setPointingToEmpty(destClasses->getAliasClassesObject()));
return;
}

for (const auto &effect : effects) {
if (!isa<MemoryEffects::Write>(effect.getEffect()))
continue;
Expand Down Expand Up @@ -860,14 +873,6 @@ void enzyme::AliasAnalysis::transfer(
result->getPoint(),
originalClasses.getOriginalClass(result->getPoint(), debugLabel));
propagateIfChanged(result, result->join(fresh));

// The pointer to freshly allocated memory is known not to point to
// anything.
// TODO(zinenko): this is a bit strange to update _another_ lattice
// here.
auto *pointsTo = getOrCreate<PointsToSets>(op);
propagateIfChanged(pointsTo, pointsTo->setPointingToEmpty(
fresh.getAliasClassesObject()));
}
}
} else if (isa<MemoryEffects::Read>(effect.getEffect())) {
Expand Down
2 changes: 1 addition & 1 deletion enzyme/test/MLIR/AliasAnalysis/func_attributes.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func.func private @callee(%ptr : !llvm.ptr {llvm.readonly}) attributes {
}

// CHECK: points-to-pointer sets
// CHECK-NEXT: <empty>
// CHECK: <empty>
// CHECK-LABEL @call_other_none_arg_rw_readonly
func.func @call_other_none_arg_rw_readonly(%input: !llvm.ptr {enzyme.tag = "input"}) {
call @callee(%input) : (!llvm.ptr) -> ()
Expand Down

0 comments on commit f7a46fd

Please sign in to comment.