================
@@ -49,40 +62,96 @@ bool CIRBasicAliasAnalysis::areDistinctObjects(mlir::Value
lhs,
mlir::AliasResult CIRBasicAliasAnalysis::alias(mlir::Value lhs,
mlir::Value rhs) {
- if (lhs == rhs)
+ LDBG() << "Checking alias between: " << lhs << " and " << rhs;
+
+ if (lhs == rhs) {
+ LDBG() << "Trivial alias between identical values";
return mlir::AliasResult::MustAlias;
+ }
- if (areDistinctObjects(lhs, rhs))
+ if (areDistinctObjects(lhs, rhs)) {
+ LDBG() << "No alias between distinct objects";
return mlir::AliasResult::NoAlias;
+ }
// Conservative fallback — the aggregate will try other implementations.
+ LDBG() << "Conservative fallback, may alias";
return mlir::AliasResult::MayAlias;
}
mlir::ModRefResult CIRBasicAliasAnalysis::getModRef(mlir::Operation *op,
mlir::Value location) {
- // Pure operations (no side effects) neither modify nor reference memory.
- if (auto effects = mlir::dyn_cast<mlir::MemoryEffectOpInterface>(op)) {
- if (effects.hasNoEffect())
+ LDBG() << "getModRef: "
+ << mlir::OpWithFlags(op, mlir::OpPrintingFlags().skipRegions())
+ << " on location " << location;
+
+ auto effects = mlir::dyn_cast<mlir::MemoryEffectOpInterface>(op);
+ if (!effects) {
+ LDBG() << "No memory effect interface, returning ModAndRef";
+ return mlir::ModRefResult::getModAndRef();
+ }
+
+ SmallVector<mlir::MemoryEffects::EffectInstance> effectList;
+ effects.getEffects(effectList);
+
+ auto classifyEffect = [location, this](
+ const mlir::MemoryEffects::EffectInstance &effect)
{
+ if (mlir::isa<mlir::MemoryEffects::Allocate>(effect.getEffect())) {
+ LDBG() << "Skipping allocate effect";
return mlir::ModRefResult::getNoModRef();
+ }
- SmallVector<mlir::MemoryEffects::EffectInstance> effectList;
- effects.getEffects(effectList);
-
- mlir::ModRefResult result = mlir::ModRefResult::getNoModRef();
- for (auto &effect : effectList) {
- // Only count effects on the queried location (or unknown location).
- mlir::Value effectVal = effect.getValue();
- if (effectVal && effectVal != location)
- continue;
- if (mlir::isa<mlir::MemoryEffects::Write>(effect.getEffect()))
- result = result.merge(mlir::ModRefResult::getMod());
- else if (mlir::isa<mlir::MemoryEffects::Read>(effect.getEffect()))
- result = result.merge(mlir::ModRefResult::getRef());
+ mlir::AliasResult aliasResult = mlir::AliasResult::MayAlias;
+ if (mlir::Value affectedLocation = effect.getValue()) {
+ LDBG() << " Checking alias between affected location "
+ << affectedLocation << " and query location " << location;
+ aliasResult = alias(affectedLocation, location);
+ LDBG() << " Alias result: "
+ << (aliasResult.isMust() ? "MustAlias"
+ : aliasResult.isNo() ? "NoAlias"
+ : "MayAlias");
+ } else {
+ // An effect on a non-addressable resource cannot affect a
+ // pointer-based location.
+ if (!effect.getResource()->isAddressable()) {
+ LDBG() << " Effect on non-addressable resource '"
+ << effect.getResource()->getName() << "', skipping (NoAlias)";
+ aliasResult = mlir::AliasResult::NoAlias;
+ } else {
+ LDBG() << " No effect value, assuming MayAlias";
+ }
}
- return result;
- }
- // Conservative fallback.
- return mlir::ModRefResult::getModAndRef();
+ // If the affected location doesn't alias wuth the query location,
----------------
bcardosolopes wrote:
wuth -> with
https://github.com/llvm/llvm-project/pull/214357
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits