#pragma once #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/IR/Value.h" #include "llvm/ADT/DenseMap.h" namespace onnx_mlir { /// Describes a value as a base addressable object plus a statically known /// byte offset after peeling aliases, casts, and contiguous subviews. struct ResolvedContiguousAddress { mlir::Value base; int64_t byteOffset = 0; }; /// Records compile-time facts used when interpreting address arithmetic and /// loop-carried aliases inside PIM regions. struct StaticValueKnowledge { llvm::DenseMap indexValues; llvm::DenseMap aliases; StaticValueKnowledge() {} }; mlir::memref::GlobalOp lookupGlobalForGetGlobal(mlir::ModuleOp moduleOp, mlir::memref::GetGlobalOp getGlobalOp); /// Resolves a value to contiguous backing storage when that storage can be /// proven statically from aliases, DPS ties, casts, and subviews. llvm::FailureOr resolveContiguousAddress(mlir::Value value); llvm::FailureOr resolveContiguousAddress(mlir::Value value, const StaticValueKnowledge& knowledge); /// Statically evaluates index-like SSA values, including simple integer /// arithmetic and loop facts recorded in `knowledge`. llvm::FailureOr resolveIndexValue(mlir::Value value); llvm::FailureOr resolveIndexValue(mlir::Value value, const StaticValueKnowledge& knowledge); /// Follows alias, view, and DPS chains to recover the backing value of a /// loop-carried memref/result. mlir::Value resolveLoopCarriedAlias(mlir::Value value, const StaticValueKnowledge& knowledge); } // namespace onnx_mlir