#include "mlir/Dialect/SPIRV/Transforms/Passes.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVTypes.h"
#include "mlir/Dialect/SPIRV/IR/TargetAndABI.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/SymbolTable.h"
#include "mlir/Transforms/DialectConversion.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Debug.h"
#include <algorithm>
#include <iterator>
namespace mlir {
namespace spirv {
#define GEN_PASS_DEF_SPIRVUNIFYALIASEDRESOURCEPASS
#include "mlir/Dialect/SPIRV/Transforms/Passes.h.inc"
}
}
#define DEBUG_TYPE …
usingnamespacemlir;
Descriptor;
AliasedResourceMap;
static AliasedResourceMap collectAliasedResources(spirv::ModuleOp moduleOp) { … }
static Type getRuntimeArrayElementType(Type type) { … }
static std::optional<int>
deduceCanonicalResource(ArrayRef<spirv::SPIRVType> types) { … }
static bool areSameBitwidthScalarType(Type a, Type b) { … }
namespace {
class ResourceAliasAnalysis { … };
}
ResourceAliasAnalysis::ResourceAliasAnalysis(Operation *root) { … }
bool ResourceAliasAnalysis::shouldUnify(Operation *op) const { … }
spirv::GlobalVariableOp ResourceAliasAnalysis::getCanonicalResource(
const Descriptor &descriptor) const { … }
spirv::GlobalVariableOp ResourceAliasAnalysis::getCanonicalResource(
spirv::GlobalVariableOp varOp) const { … }
spirv::SPIRVType
ResourceAliasAnalysis::getElementType(spirv::GlobalVariableOp varOp) const { … }
void ResourceAliasAnalysis::recordIfUnifiable(
const Descriptor &descriptor, ArrayRef<spirv::GlobalVariableOp> resources) { … }
template <typename OpTy>
class ConvertAliasResource : public OpConversionPattern<OpTy> { … };
struct ConvertVariable : public ConvertAliasResource<spirv::GlobalVariableOp> { … };
struct ConvertAddressOf : public ConvertAliasResource<spirv::AddressOfOp> { … };
struct ConvertAccessChain : public ConvertAliasResource<spirv::AccessChainOp> { … };
struct ConvertLoad : public ConvertAliasResource<spirv::LoadOp> { … };
struct ConvertStore : public ConvertAliasResource<spirv::StoreOp> { … };
namespace {
class UnifyAliasedResourcePass final
: public spirv::impl::SPIRVUnifyAliasedResourcePassBase<
UnifyAliasedResourcePass> { … };
void UnifyAliasedResourcePass::runOnOperation() { … }
}
std::unique_ptr<mlir::OperationPass<spirv::ModuleOp>>
spirv::createUnifyAliasedResourcePass(spirv::GetTargetEnvFn getTargetEnv) { … }