26#ifndef ENZYME_MLIR_ANALYSIS_DATAFLOW_ALIASANALYSIS_H
27#define ENZYME_MLIR_ANALYSIS_DATAFLOW_ALIASANALYSIS_H
31#include "mlir/Analysis/AliasAnalysis.h"
32#include "mlir/Analysis/DataFlow/DenseAnalysis.h"
33#include "mlir/Analysis/DataFlow/SparseAnalysis.h"
34#include "mlir/Analysis/DataFlowFramework.h"
35#include "mlir/Interfaces/SideEffectInterfaces.h"
39class CallableOpInterface;
60 StringAttr::get(value.getContext(), debugLabel));
63 DistinctAttr &aliasClass = originalClasses[value];
66 referenced = UnitAttr::get(value.getContext());
67 aliasClass = DistinctAttr::create(referenced);
76 auto label = StringAttr::get(values.front().getContext(), debugLabel);
78 DistinctAttr common =
nullptr;
79 for (Value v : values) {
80 DistinctAttr &aliasClass = originalClasses[v];
83 common = DistinctAttr::create(label);
89 assert(aliasClass == common &&
"original alias class mismatch");
96 DenseMap<Value, DistinctAttr> originalClasses;
108 using MapOfSetsLattice::MapOfSetsLattice;
110 void print(raw_ostream &os)
const override;
116 return update(destClasses, values,
true);
123 return update(destClasses, values,
false);
169 :
public dataflow::DenseForwardDataFlowAnalysis<PointsToSets> {
180 dataflow::CallControlFlowAction action,
185 Value capturedValue, Value destinationAddress,
189 CallOpInterface call,
190 const DenseMap<DistinctAttr, AliasClassSet> &summary,
209 void print(raw_ostream &os)
const override;
232 :
public dataflow::SparseForwardDataFlowAnalysis<AliasClassLattice> {
234 AliasAnalysis(DataFlowSolver &solver, MLIRContext *ctx,
bool relative =
false)
236 entryClass(DistinctAttr::create(StringAttr::get(ctx,
"entry"))),
239 assert(!solver.getConfig().isInterprocedural());
245 ArrayRef<const AliasClassLattice *> operands,
246 ArrayRef<AliasClassLattice *> results)
override;
249 ArrayRef<const AliasClassLattice *> operands,
250 ArrayRef<AliasClassLattice *> results)
override;
253 void transfer(Operation *op, ArrayRef<MemoryEffects::EffectInstance> effects,
254 ArrayRef<const AliasClassLattice *> operands,
255 ArrayRef<AliasClassLattice *> results);
262 DistinctAttr srcClass,
266 const DistinctAttr entryClass;
static bool isMustStore(Operation *op, Value pointer)
This analysis implements interprocedural alias analysis.
LogicalResult visitOperation(Operation *op, ArrayRef< const AliasClassLattice * > operands, ArrayRef< AliasClassLattice * > results) override
void visitExternalCall(CallOpInterface call, ArrayRef< const AliasClassLattice * > operands, ArrayRef< AliasClassLattice * > results) override
AliasAnalysis(DataFlowSolver &solver, MLIRContext *ctx, bool relative=false)
void setToEntryState(AliasClassLattice *lattice) override
const AliasClassSet & getAliasClassesObject() const
void print(raw_ostream &os) const override
const DenseSet< DistinctAttr > & getAliasClasses() const
ChangeResult join(const AbstractSparseLattice &other) override
static AliasClassLattice single(Value point, DistinctAttr value)
::mlir::AliasResult alias(const AbstractSparseLattice &other) const
ChangeResult markAllUnknown()
const SetLattice< DistinctAttr > & lookup(DistinctAttr key) const
Alias classes for freshly created, e.g., allocated values.
DistinctAttr getSameOriginalClass(ValueRange values, StringRef debugLabel)
DistinctAttr getOriginalClass(Value value, Attribute referenced=nullptr)
DistinctAttr getOriginalClass(Value value, StringRef debugLabel)
void processCallToSummarizedFunc(CallOpInterface call, const DenseMap< DistinctAttr, AliasClassSet > &summary, PointsToSets *after)
void setToEntryState(PointsToSets *lattice) override
void processCapturingStore(ProgramPoint *dependent, PointsToSets *after, Value capturedValue, Value destinationAddress, bool isMustStore=false)
LogicalResult visitOperation(Operation *op, const PointsToSets &before, PointsToSets *after) override
void visitCallControlFlowTransfer(CallOpInterface call, dataflow::CallControlFlowAction action, const PointsToSets &before, PointsToSets *after) override
PointsToPointerAnalysis(DataFlowSolver &solver)
ChangeResult insert(const AliasClassSet &destClasses, const AliasClassSet &values)
Mark the pointer stored in dest as possibly pointing to any of values, in addition to the values it m...
const AliasClassSet & getPointsTo(DistinctAttr id) const
ChangeResult markAllExceptPointToUnknown(const AliasClassSet &destClasses)
Mark all alias classes except the given ones to point to the "unknown" alias set.
ChangeResult setPointingToClasses(const AliasClassSet &destClasses, const AliasClassSet &values)
Mark the pointer stored in dest as possibly pointing to any of values, instead of the values it may b...
ChangeResult markAllPointToUnknown()
Mark the entire data structure as "unknown", that is, any pointer may be containing any other pointer...
ChangeResult markPointToUnknown(const AliasClassSet &destClasses)
Mark dest as pointing to "unknown" alias set, that is, any possible other pointer.
ChangeResult setPointingToEmpty(const AliasClassSet &destClasses)
void print(raw_ostream &os) const override
ChangeResult addSetsFrom(const AliasClassSet &destClasses, const AliasClassSet &srcClasses)
For every alias class in dest, record that it may additionally be pointing to the same as the classes...
DenseSet< ValueT > & getElements()
SparseSetLattice(Value value, SetLattice< ValueT > &&elements)
SetLattice< DistinctAttr > elements
SetLattice< DistinctAttr > AliasClassSet
A set of alias class identifiers to be treated as a single union.