Lines Matching refs:spirv
41 DenseMap<Descriptor, SmallVector<spirv::GlobalVariableOp>>;
44 static AliasedResourceMap collectAliasedResources(spirv::ModuleOp moduleOp) { in collectAliasedResources()
46 moduleOp->walk([&aliasedResources](spirv::GlobalVariableOp varOp) { in collectAliasedResources()
60 auto ptrType = type.dyn_cast<spirv::PointerType>(); in getRuntimeArrayElementType()
64 auto structType = ptrType.getPointeeType().dyn_cast<spirv::StructType>(); in getRuntimeArrayElementType()
69 structType.getElementType(0).dyn_cast<spirv::RuntimeArrayType>(); in getRuntimeArrayElementType()
79 static Optional<int> deduceCanonicalResource(ArrayRef<spirv::SPIRVType> types) { in deduceCanonicalResource()
85 for (spirv::SPIRVType type : types) { in deduceCanonicalResource()
164 spirv::GlobalVariableOp
166 spirv::GlobalVariableOp
167 getCanonicalResource(spirv::GlobalVariableOp varOp) const;
170 spirv::SPIRVType getElementType(spirv::GlobalVariableOp varOp) const;
176 ArrayRef<spirv::GlobalVariableOp> resources);
182 DenseMap<Descriptor, spirv::GlobalVariableOp> canonicalResourceMap;
185 DenseMap<spirv::GlobalVariableOp, Descriptor> descriptorMap;
188 DenseMap<spirv::GlobalVariableOp, spirv::SPIRVType> elementTypeMap;
196 collectAliasedResources(cast<spirv::ModuleOp>(root)); in ResourceAliasAnalysis()
206 if (auto varOp = dyn_cast<spirv::GlobalVariableOp>(op)) { in shouldUnify()
210 if (auto addressOp = dyn_cast<spirv::AddressOfOp>(op)) { in shouldUnify()
211 auto moduleOp = addressOp->getParentOfType<spirv::ModuleOp>(); in shouldUnify()
216 if (auto acOp = dyn_cast<spirv::AccessChainOp>(op)) in shouldUnify()
218 if (auto loadOp = dyn_cast<spirv::LoadOp>(op)) in shouldUnify()
220 if (auto storeOp = dyn_cast<spirv::StoreOp>(op)) in shouldUnify()
226 spirv::GlobalVariableOp ResourceAliasAnalysis::getCanonicalResource( in getCanonicalResource()
234 spirv::GlobalVariableOp ResourceAliasAnalysis::getCanonicalResource( in getCanonicalResource()
235 spirv::GlobalVariableOp varOp) const { in getCanonicalResource()
242 spirv::SPIRVType
243 ResourceAliasAnalysis::getElementType(spirv::GlobalVariableOp varOp) const { in getElementType()
251 const Descriptor &descriptor, ArrayRef<spirv::GlobalVariableOp> resources) { in recordIfUnifiable()
253 SmallVector<spirv::SPIRVType> elementTypes; in recordIfUnifiable()
254 for (spirv::GlobalVariableOp resource : resources) { in recordIfUnifiable()
259 auto type = elementType.cast<spirv::SPIRVType>(); in recordIfUnifiable()
294 struct ConvertVariable : public ConvertAliasResource<spirv::GlobalVariableOp> {
298 matchAndRewrite(spirv::GlobalVariableOp varOp, OpAdaptor adaptor, in matchAndRewrite()
307 struct ConvertAddressOf : public ConvertAliasResource<spirv::AddressOfOp> {
311 matchAndRewrite(spirv::AddressOfOp addressOp, OpAdaptor adaptor, in matchAndRewrite()
314 auto moduleOp = addressOp->getParentOfType<spirv::ModuleOp>(); in matchAndRewrite()
315 auto srcVarOp = cast<spirv::GlobalVariableOp>( in matchAndRewrite()
318 rewriter.replaceOpWithNewOp<spirv::AddressOfOp>(addressOp, dstVarOp); in matchAndRewrite()
323 struct ConvertAccessChain : public ConvertAliasResource<spirv::AccessChainOp> {
327 matchAndRewrite(spirv::AccessChainOp acOp, OpAdaptor adaptor, in matchAndRewrite()
329 auto addressOp = acOp.base_ptr().getDefiningOp<spirv::AddressOfOp>(); in matchAndRewrite()
333 auto moduleOp = acOp->getParentOfType<spirv::ModuleOp>(); in matchAndRewrite()
334 auto srcVarOp = cast<spirv::GlobalVariableOp>( in matchAndRewrite()
338 spirv::SPIRVType srcElemType = analysis.getElementType(srcVarOp); in matchAndRewrite()
339 spirv::SPIRVType dstElemType = analysis.getElementType(dstVarOp); in matchAndRewrite()
345 rewriter.replaceOpWithNewOp<spirv::AccessChainOp>( in matchAndRewrite()
362 auto ratioValue = rewriter.create<spirv::ConstantOp>( in matchAndRewrite()
368 rewriter.create<spirv::SDivOp>(loc, i32Type, oldIndex, ratioValue); in matchAndRewrite()
370 rewriter.create<spirv::SModOp>(loc, i32Type, oldIndex, ratioValue)); in matchAndRewrite()
372 rewriter.replaceOpWithNewOp<spirv::AccessChainOp>( in matchAndRewrite()
385 auto ratioValue = rewriter.create<spirv::ConstantOp>( in matchAndRewrite()
391 rewriter.create<spirv::IMulOp>(loc, i32Type, oldIndex, ratioValue); in matchAndRewrite()
393 rewriter.replaceOpWithNewOp<spirv::AccessChainOp>( in matchAndRewrite()
402 struct ConvertLoad : public ConvertAliasResource<spirv::LoadOp> {
406 matchAndRewrite(spirv::LoadOp loadOp, OpAdaptor adaptor, in matchAndRewrite()
409 loadOp.ptr().getType().cast<spirv::PointerType>().getPointeeType(); in matchAndRewrite()
411 adaptor.ptr().getType().cast<spirv::PointerType>().getPointeeType(); in matchAndRewrite()
416 auto newLoadOp = rewriter.create<spirv::LoadOp>(loc, adaptor.ptr()); in matchAndRewrite()
423 auto castOp = rewriter.create<spirv::BitcastOp>(loc, srcElemType, in matchAndRewrite()
445 auto acOp = adaptor.ptr().getDefiningOp<spirv::AccessChainOp>(); in matchAndRewrite()
450 Value oneValue = spirv::ConstantOp::getOne(i32Type, loc, rewriter); in matchAndRewrite()
454 indices.back() = rewriter.create<spirv::IAddOp>(loc, i32Type, in matchAndRewrite()
457 rewriter.create<spirv::AccessChainOp>(loc, acOp.base_ptr(), indices); in matchAndRewrite()
460 components.push_back(rewriter.create<spirv::LoadOp>(loc, componentAcOp)); in matchAndRewrite()
467 Value vectorValue = rewriter.create<spirv::CompositeConstructOp>( in matchAndRewrite()
469 rewriter.replaceOpWithNewOp<spirv::BitcastOp>(loadOp, srcElemType, in matchAndRewrite()
475 struct ConvertStore : public ConvertAliasResource<spirv::StoreOp> {
479 matchAndRewrite(spirv::StoreOp storeOp, OpAdaptor adaptor, in matchAndRewrite()
482 storeOp.ptr().getType().cast<spirv::PointerType>().getPointeeType(); in matchAndRewrite()
484 adaptor.ptr().getType().cast<spirv::PointerType>().getPointeeType(); in matchAndRewrite()
493 value = rewriter.create<spirv::BitcastOp>(loc, dstElemType, value); in matchAndRewrite()
494 rewriter.replaceOpWithNewOp<spirv::StoreOp>(storeOp, adaptor.ptr(), value, in matchAndRewrite()
513 spirv::ModuleOp moduleOp = getOperation(); in runOnOperation()
520 target.addDynamicallyLegalOp<spirv::GlobalVariableOp, spirv::AddressOfOp, in runOnOperation()
521 spirv::AccessChainOp, spirv::LoadOp, in runOnOperation()
522 spirv::StoreOp>( in runOnOperation()
524 target.addLegalDialect<spirv::SPIRVDialect>(); in runOnOperation()
537 collectAliasedResources(cast<spirv::ModuleOp>(moduleOp)); in runOnOperation()
545 std::unique_ptr<mlir::OperationPass<spirv::ModuleOp>>
546 spirv::createUnifyAliasedResourcePass() { in createUnifyAliasedResourcePass()